我有以下ggplot。
mu1_mu2_violin_onset <- age[which(age$Status=="2" & (age$Diet=="wt" | age_onset$Diet=="mu2" | age_onset$Diet=="mu1")), ]
onset_mu1_mu2_final=ggplot(data=mu1_mu2_violin_onset, aes(x=Diet, y=Age, fill=Diet)) +
geom_violin() + stat_summary(fun.data=data_summary) + theme_bw() + theme_classic() +
scale_color_brewer(palette="Dark2") +scale_fill_brewer(palette="Blues")+ theme(axis.text=element_text(family="sans", size=18),axis.line.x = element_line(color="black"), axis.line.y= element_line(color="black"), legend.position="none", axis.title=element_text(family="sans", size=18), panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
scale_y_continuous(name="Age") + scale_x_discrete(name="",limits=c("mu2","mu1","control"),labels=expression(italic(mu2),italic(mu1),WT))
spag= onset_mu1_mu2_final + coord_flip()
onset_mu1_mu2=spag + facet_grid(Sex~ ., switch="y") +
theme(strip.text.y = element_text(size=18, angle=180),
strip.background = element_rect(colour="white"))
# T-test
violin_onset_F_mu1 <- mu1_mu2_violin_onset[which(mu1_mu2_violin_onset$Sex=="F" & (mu1_mu2_violin_onset$Diet=="mu1" | mu1_mu2_violin_onset$Diet=="wt)),]
t.test(violin_onset_F_mu1$Age~violin_onset_F_mu1$Diet,var.equal=T)$p.value
violin_onset_M_mu1 <- mu1_mu2_violin_onset[which(mu1_mu2_violin_onset$Sex=="M" & (mu1_mu2_violin_onset$Diet=="mu1" | mu1_mu2_violin_onset$Diet=="wt)),]
t.test(violin_onset_M_mu1$Age~violin_onset_M_mu1$Diet,var.equal=T)$p.value
violin_onset_F_mu2 <- mu1_mu2_violin_onset[which(mu1_mu2_violin_onset$Sex=="F" & (mu1_mu2_violin_onset$Diet=="mu2" | mu1_mu2_violin_onset$Diet=="wt)),]
t.test(violin_onset_F_mu2$Age~violin_onset_F_mu2$Diet,var.equal=T)$p.value
violin_onset_M_mu2 <- mu1_mu2_violin_onset[which(mu1_mu2_violin_onset$Sex=="M" & (mu1_mu2_violin_onset$Diet=="mu2" | mu1_mu2_violin_onset$Diet=="wt)),]
t.test(violin_onset_M_mu2$Age~violin_onset_M_mu2$Diet,var.equal=T)$p.value
我正在尝试添加t.test Pvalues和&#34; F&#34;,&#34; M&#34;文字中以红色显示的文字。
我已尝试以下方法添加pvalues:
ann_text <- data.frame(Diet=c(0.90,0.69,0.24,0.03),Age_onset=c(12.4, 21.4, 15.2, 13.6),lab=c("Pvalue 1", "Pvalue 2", "Pvalue 3","Pvalue 4"), Sex=factor(c("F_mu1","F_mu2", "M_mu1", "M_mu2"),levels=c("F_mu1","F_mu2","M_mu1", "M_mu2")))
onset_mu1_mu2 + geom_text(data = ann_text,aes(label =lab))
但是我收到以下错误:
Error: Continuous value supplied to discrete scale
我怎么能克服这个问题?谢谢,