R 如何使用多行文字在分组条形图的条形图上添加值?

R 如何使用多行文字在分组条形图的条形图上添加值?,r,plot,R,Plot,如何使用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

如何使用
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. 
 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.
#分组条形图

计数嗯,
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. 
 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.

bplt@Manish如果这个答案适合你(正如你在对自己问题的评论中所指出的),那么你应该接受这个答案。