سؤال

أنا أبحث عن طريقة لإضافة ملصقات ، أي القيم المطلقة ، في مخطط شريط مكدسة باستخدام وظائف المؤامرة الأساسية لـ R. يجب أن تكون الملصقات داخل الأشرطة المكدسة.

شكرًا لك!

هل كانت مفيدة؟

المحلول

barplot سيعود موقع Mid X من القضبان ، حتى تتمكن من القيام به

mydata <- matrix(c(10, 21, 22, 33, 45, 23, 22, 43, 33), nrow=3)

# b will contain the x midpoints of the bars
b <- barplot(mydata)

# This will write labels in the middle of the bars, horizontally and vertically
text(b, colMeans(mydata), c("Label1", "Label2", "Label3"))

# This will write labels in the middle of the middle block
text(b, mydata[1,]+mydata[2,]/2, c("LabelA", "LabelB", "LabelC"))

تعديل: أعد قراءة سؤالك ، أعتقد أن هذا ما تريده (أو ربما لا ، لكنني سأكتبه على أي حال: D)

# Find the top y position of each block 
ypos <- apply(mydata, 2, cumsum)
# Move it downwards half the size of each block
ypos <- ypos - mydata/2
ypos <- t(ypos)

text(b, ypos, mydata)

نصائح أخرى

ماذا عن الوظيفة البسيطة text()?

يمكنك ببساطة إضافة سلسلة أينما تريد ، على سبيل المثال:

text (x = ..., y = ..., labels = c("foo bar 1000"))

ربما يمكنك استخدام أو فحص بارب وظيفة Plotrix صفقة

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top