【问题标题】:plot number of data points in r绘制 r 中的数据点数
【发布时间】:2015-06-30 12:58:53
【问题描述】:

我在 R 中使用以下内容从给定的数据集生成箱线图:

ggplot(data = daten, aes(x=Bodentyp, y=Fracht)) + geom_boxplot(aes(fill=Bewirtschaftungsform))

现在我想显示进入“Bodentyp”列的每个类别的数据点数。我如何做到这一点?

【问题讨论】:

  • 我不太确定您到底想要什么(也许一些数据和/或预期的(视觉)输出会有所帮助),但添加geom_jitter(aes(colour = Bewirtschaftungsform)) 是否可以满足您的需求?

标签: r ggplot2 boxplot


【解决方案1】:

您可以使用 fun.data 将函数 (f) 应用于分组数据以返回计数 (length(y)) 和标签位置 (median(y))

f <- function(y) 
    c(label=length(y), y=median(y))

library(ggplot2)
data(mtcars)
ggplot(mtcars, aes(x=as.factor(cyl), y=mpg)) +
  geom_boxplot() + theme_bw() +
  stat_summary(fun.data=f, geom="text", vjust=-0.5, col="blue")

【讨论】:

    猜你喜欢
    • 2015-01-24
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-26
    • 1970-01-01
    相关资源
    最近更新 更多