【发布时间】:2021-02-04 16:25:11
【问题描述】:
按照this post 的示例,我的目标是仅在 p 值低于某个阈值时标记比较。在终于让它工作之后,我看到它正在抵消之前设置的 ggplot 参数并且不再能够找到填充变量。
我已经包含了一个可重现的示例和我想要的输出。
set.seed(20)
col1<-c(rep('E', each = 8))
col2<-c(rep('R', each = 8))
col3<-c(rep('S', each = 8))
behaviour<-c(col1,col2,col3)
value <- runif(length(behaviour), min=2, max=8)
shannon <- c(rep('Shannon', each = length(behaviour)))
test.data <- data.frame(behaviour, value, shannon)
d <- compare_means(value~behaviour, data = test.data,method = 't.test')
d %<>% mutate(y_pos = c(5,5.5,6),labels = ifelse(p<0.17,p.format,p.signif))
d
.y. group1 group2 p p.adj p.format p.signif method y_pos labels
value E R 0.4678791 0.76 0.47 ns T-test 5.0 ns
value E S 0.1559682 0.47 0.16 ns T-test 5.5 0.16
value R S 0.3794209 0.76 0.38 ns T-test 6.0 ns
shannonviolin<-ggplot(test.data, aes(x = behaviour, y = value)) +
labs(y= "Shannon",color = " ",size=8)+
geom_violin(position=position_dodge(width=1.2),alpha = 0.7,scale="width",adjust=0.9,trim=FALSE)+
geom_boxplot(width=0.4,outlier.colour = "transparent")+
geom_point(aes(fill = behaviour), size = 5, shape = 21, position = position_jitterdodge()) +
theme_classic()+
scale_fill_manual(values = c("E" = '#3797a4', "R"= '#96bb7c',"S"= '#944e6c'))+
theme(text = element_text(size = 18),
axis.title.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
legend.position = "right",
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
legend.title = element_blank()
)+
ylim(0, 14)
shannonviolin+geom_signif(data = as.data.frame(d), tip_length = 0.01, aes(xmin=group1, xmax=group2, annotations=labels,y_position=c(12.4,13,13.6)),manual=TRUE)
这让它开始工作:
但是没有填充颜色。如果我在 ggplot 中指定填充参数:
shannonviolinfill<-ggplot(test.data, aes(x = behaviour, y = value,fill=behaviour)) +
labs(y= "Shannon",color = " ",size=8)+
geom_violin(position=position_dodge(width=1.2),alpha = 0.7,scale="width",adjust=0.9,trim=FALSE)+
geom_boxplot(width=0.4,outlier.colour = "transparent")+
geom_point(aes(fill = behaviour), size = 5, shape = 21, position = position_jitterdodge()) +
theme_classic()+
scale_fill_manual(values = c("E" = '#3797a4', "R"= '#96bb7c',"S"= '#944e6c'))+
theme(text = element_text(size = 18),
axis.title.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
legend.position = "right",
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
legend.title = element_blank()
)+
ylim(0, 14)
shannonviolinfill+geom_signif(data = as.data.frame(d), tip_length = 0.01, aes(xmin=group1, xmax=group2, annotations=labels,y_position=c(12.4,13,13.6)),manual=TRUE)
我得到的错误是
ERROR while rich displaying an object: Error: Aesthetics must be either length 1 or the same as the data (3): fill
理想情况下应该是这样的:
如果有人知道黑客或解决方法,我将不胜感激,因为我整天都在绕着下水道转!
【问题讨论】: