如何在facet_wrap

时间:2018-11-30 14:40:52

标签: r ggplot2 facet-wrap geom-text tukeyhsd

我用我的数据进行了 ggplot 。比我想标记我的箱线图数据之间的一些交互(通过anova / Tukey)来显示,无论特殊组之间是否存在显着差异。我正在处理一个已导入的csv工作表,即“ test”,并且正在处理一个称为“ final”的表格

[enter image description here

[enter image description here

但是当我使用来自TukeyHSD的标签绘制数据时,我得到的每个标签都是三元组,每个空格都是空白。

enter image description here

我如何删除空白处。必须有任何解决方案才能在第一个图中显示带有标签的第一条树线,在中间图中显示带有特定标签的中间树线,以及在第三处显示带有标签的最后树线。如何删除带有空字体标签的空行?

这是我的代码:

test$int<-interaction(test$geno,test$n)
generate_label_df <- function(TUKEY, variable){
Tukey.levels <- TUKEY[[variable]][,4]
Tukey.labels <- data.frame(multcompLetters(Tukey.levels)['Letters'])
Tukey.labels$int=rownames(Tukey.labels)
Tukey.labels=Tukey.labels[order(Tukey.labels$int) , ]
return(Tukey.labels)
}
model=lm(test$amino~test$int ) ###
ANOVA=aov(model)
TUKEY <- TukeyHSD(x=ANOVA, 'test$int', conf.level=0.95)
labels<-generate_label_df(TUKEY , "test$int")
names(labels)<-c('Letters','int')
yvalue<-aggregate(amino~int, data=test, max)
final<-merge(labels,yvalue) 

ggplot(test, aes(x=int, y=amino)) + 
  stat_boxplot(geom="errorbar") + 
  geom_boxplot(aes(fill=CO2)) + 
  geom_text(data = final, aes(label = Letters, vjust = -0.6)) +
  labs(title = "Aminosäuren Erdkultur", x = "Genotyp", y = "Aminosäurekonz. [µmol/gFW]") +
  scale_x_discrete(labels = c("col.Ammonium" = "col", "sps.Ammonium" = "sps",
                              "swe.Ammonium" = "swe", "col.Nitrat" = "col", 
                              "sps.Nitrat" = "sps", "swe.Nitrat" = "swe",
                              "col.NON" = "col", "sps.NON" = "sps","swe.NON" = "swe"),
                   limits = c("col.Ammonium", "sps.Ammonium", "swe.Ammonium", 
                              "col.Nitrat", "sps.Nitrat","swe.Nitrat", "col.NON", 
                              "sps.NON", "swe.NON") )+
  guides(fill = guide_legend(title = "CO2-Behandlung")) +
  theme(plot.title = element_text(face = "bold", size="17", hjust = "0.5")) +
  scale_fill_manual(values = c("violetred3", "steelblue1")) +
  facet_wrap( ~ n) +
  theme(legend.title = element_text(face = "bold"))

我的第一意见是删除“ facet_wrap(〜n)”。问题比解决了,但是很明显我缺少这种细分方式

enter image description here

0 个答案:

没有答案