如何使用 mtext
在柱上写入值?
# Grouped Bar Plot
counts <- table(mtcars$vs, mtcars$gear)
barplot(counts, main="Car Distribution by Gears and VS",xlab="Number of Gears", col=c("darkblue","red"),legend = rownames(counts), beside=TRUE, horiz=TRUE)
mtext(counts ) # But position is not at each bar.
如何在每个条形图上放置相应的值?
最佳答案
那么,mtext
通常用于边距。您是否有不想使用的原因 text
?
bplt <- barplot(counts,
main="Car Distribution by Gears and VS", xlab="Number of Gears",
col=c("darkblue","red"), legend = rownames(counts),
beside=TRUE, horiz=TRUE)
# variable 'bplt' is now a matrix of vertical bar positions on the y-axis
text(x= counts+0.3, y= bplt, labels=as.character(counts), xpd=TRUE)
# Needed to use xpd=TRUE because the xlimits were too narrow.
关于r - 如何使用多行文本在分组条形图的条形上添加值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11911506/