在条形图中显示元素值 [英] Show element values in barplot

查看:74
本文介绍了在条形图中显示元素值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将原始计数放入条形图中,但它总是很杂乱:

I'm trying to put original counts into a barplot, but it's always messy:

set.seed(123)
c<-c(2, 3.5, 5, 7.9, 8.8, 12.3)
x<-sample(c, 100, replace=T)
barplot(table(x))
text(c, table(x)+2, labels=as.character(table(x)))

有人会建议吗?

推荐答案

您只需要确保ylim足够大,这样就不会将任何文本放置在绘图区域之外,然后您需要条中间的位置,并确保将文本放置在此处.

You just need to make sure that ylim is large enough such that none of the text will be placed outside of the plot area, and then you need the positions of the middle of bars and make sure to place the text there.

set.seed(123)
origin <-c(2, 3.5, 5, 7.9, 8.8, 12.3)
x<-sample(origin, 100, replace=T)
b<-barplot(table(x),ylim=c(0,22))
text(x=b, y= table(x)+1, labels=as.character(table(x)))

这篇关于在条形图中显示元素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆