我正在寻找一种使用R的基本绘图功能在堆叠条形图中添加标签(即绝对值)的方法。这些标签应该位于堆叠的条形内部。
谢谢!
谢谢!
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"))
# 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"))