【问题标题】:Adding Tukey's significance letters to boxplot将 Tukey 的重要字母添加到箱线图中
【发布时间】:2018-02-05 15:14:38
【问题描述】:

我正在尝试创建一个箱线图,其中 yaxis 上的计数 (MedMean) 和 xaxis 上的各种独立样本 (Site_Name) 的 ggplot。

ggplot(medianlist,aes(x=reorder(Site_Name,MedMean,FUN=median),y=MedMean))+
geom_boxplot()

我想将 Tukey 的重要字母添加到方框中。

谢谢

【问题讨论】:

  • 来个可重现的例子怎么样?
  • ggplot(iris,aes(x=reorder(Species,Petal.Length,FUN = 中位数),y=Petal.Length))+geom_boxplot()
  • 这与使用“iris”文件的功能相同。我想添加显示物种之间重要性的字母(在本例中)

标签: r ggplot2 posthoc tukey


【解决方案1】:

使用agricolae::HSD.test 你可以做到

library(dplyr)
library(agricolae)
library(ggplot2)
iris.summarized = iris %>% group_by(Species) %>% summarize(Max.Petal.Length=max(Petal.Length))
hsd=HSD.test(aov(Petal.Length~Species,data=iris), "Species", group=T)
ggplot(iris,aes(x=reorder(Species,Petal.Length,FUN = median),y=Petal.Length))+geom_boxplot()+geom_text(data=iris.summarized,aes(x=Species,y=0.2+Max.Petal.Length,label=hsd$groups$groups),vjust=0)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-14
    • 2016-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多