如何用条形码写入值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.
Run Code Online (Sandbox Code Playgroud)
如何在每个条形图上添加相应的值?
42-*_*42- 19
好吧,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.
Run Code Online (Sandbox Code Playgroud)
