geom_文本适用于R中的直方图?
想知道geom_文本适用于R中的直方图?,r,ggplot2,histogram,R,Ggplot2,Histogram,想知道geom_text是否适用于hist?尝试了以下代码,但似乎没有效果。我只想在为每个直方图桶绘制每个条形图时显示标签(属于特定直方图桶的元素数量)。欢迎提供任何解决方案。谢谢 p <- hist(df$foo, main="title",xlab="foo") p + geom_text() 问候,, 林既然没有人回答这个问题,我就试试看: 首先,有几点建议: 发布您的数据将使人们更有可能回答(因此我们不必重复) 自己做一些研究会有很大的帮助。例如,您提到您
geom_text
是否适用于hist
?尝试了以下代码,但似乎没有效果。我只想在为每个直方图桶绘制每个条形图时显示标签(属于特定直方图桶的元素数量)。欢迎提供任何解决方案。谢谢
p <- hist(df$foo,
main="title",xlab="foo")
p + geom_text()
问候,,
林既然没有人回答这个问题,我就试试看: 首先,有几点建议:
- 发布您的数据将使人们更有可能回答(因此我们不必重复)
- 自己做一些研究会有很大的帮助。例如,您提到您希望每个酒吧都有一个标签-很好,有几种方法可以做到这一点。谷歌快速搜索发现:
set.seed(1)
#Make sample data since none is provided
df <- data.frame(foo=sample(1:10,200,replace=T))
#This is what you want - use as.factor(foo) - this gives you the breaks at every bar.
g <- ggplot(df, aes(as.factor(foo)))
#Actually making the barplot and adding labels to it
g + geom_bar() +stat_count(aes(y=..count..,label=..count..),geom="text",vjust=-1)
set.seed(1)
#由于未提供任何示例数据,请创建示例数据
df从ggplot2
软件包中检出geom_条形图
geom_text
和hist
不能一起使用。@MikeyMike,谢谢,想知道如果我使用hist
,是否有解决方案?可能重复(如果你想要直方图):条形图可能重复:我想@Gregor的第一条评论是你想要的。谢谢MikeyMike,请投票并将你的回答标记为答案。
set.seed(1)
#Make sample data since none is provided
df <- data.frame(foo=sample(1:10,200,replace=T))
#This is what you want - use as.factor(foo) - this gives you the breaks at every bar.
g <- ggplot(df, aes(as.factor(foo)))
#Actually making the barplot and adding labels to it
g + geom_bar() +stat_count(aes(y=..count..,label=..count..),geom="text",vjust=-1)