ggplot2给并排条形图自定义添加P值
2021-06-10 本文已影响0人
R语言数据分析指南
分享一个给并排条形图添加P值得小栗子,此方法略微繁琐但是方便初学者理解,希望对大家有所帮助
avsnp147 case-mut_number no_case ctrl-mut_number no_ctrl .
1 rs1801133 101 44 68 51 *
2 rs949882 101 44 53 66 ****
3 rs1166698 95 50 52 67 ***
4 rs10963 94 51 53 66 **
5 rs2228528 103 42 65 54 **
6 rs2808096 73 72 82 37 **
7 rs9896398 88 57 89 30 *
bar %>% select(avsnp147:non_N) %>%
melt() %>% filter(variable != "non_H") %>%
filter(variable != "non_N") %>%
ggplot(aes(avsnp147,value,fill=variable))+
geom_bar(stat="identity",
position=position_dodge(),width = 0.6)+
labs(x=NULL,y=NULL,fill=NULL)+
scale_y_continuous(limits = c(0,110),expand = c(0, 0))+
theme_classic()+
annotate("text",x = 1, y =96, label = "*",
size = 6, color = "#22292F")+
annotate("text",x = 2, y =97, label = "****",
size = 6, color = "#22292F")+
annotate("text",x = 3, y =103, label = "****",
size = 6, color = "#22292F")+
annotate("text",x = 4, y =105, label = "**",
size = 6, color = "#22292F")+
annotate("text",x = 5, y =84, label = "**",
size = 6, color = "#22292F")+
annotate("text",x = 6, y =103, label = "***",
size = 6, color = "#22292F")+
annotate("text",x = 7, y =91, label = "*",
size = 6, color = "#22292F")+
geom_segment(aes(x =0.8, y =95, xend = 1.2, yend = 95))+
geom_segment(aes(x =1.8, y =96, xend = 2.2, yend = 96))+
geom_segment(aes(x =2.8, y =102, xend = 3.2, yend =102))+
geom_segment(aes(x =3.8, y =104, xend = 4.2, yend = 104))+
geom_segment(aes(x =4.8, y =83, xend = 5.2, yend = 83))+
geom_segment(aes(x =5.8, y =102, xend = 6.2, yend = 102))+
geom_segment(aes(x =6.8, y =90, xend = 7.2, yend = 90))+
scale_fill_manual(values=c("#F98400","#046C9A"))
![](https://img.haomeiwen.com/i16360488/3a9a1b5c468a5a8c.png)