0
点赞
收藏
分享

微信扫一扫

ggplot2自定义添加P值

路西法阁下 2021-09-19 阅读 124
library(tidyverse)
library(reshape)
library(ggsignif)

ggsingif来进行一个统计检验

ggplot(iris,aes(Species,Sepal.Length,fill=Species)) + 
geom_boxplot()+geom_jitter(shape=16,size=2,
position=position_jitter(0.2))+
  geom_signif(comparisons = list(c("versicolor", "virginica"),
                                 c("versicolor","setosa"),
                                 c("virginica","setosa")),
              map_signif_level=T,
              textsize=6,test=wilcox.test,step_increase=0.2)+
  guides(fill=FALSE)+xlab(NULL)+theme_classic()

自定义线条位点

p_value1 <- tibble(
  x = c("Sepal.Length","Sepal.Length","Petal.Length","Petal.Length"),
  y= c(890,910,910,700))

p_value2 <- tibble(
  x = c("Sepal.Width","Sepal.Width","Petal.Width","Petal.Width"),
  y=c(480,600,600,190))
iris %>% melt() %>% ggplot(aes(variable,value))+
  geom_col(width = 0.5)+
  theme_classic()+
  scale_y_continuous(limits = c(0,950), expand = c(0, 0))+
  geom_line(data = p_value1, aes(x = x, y = y,group=1))+
  geom_line(data = p_value2, aes(x = x, y = y,group=1))+
  annotate("text", x = 2, y = 920, label = "***",
           size = 6, color = "#22292F")+
  annotate("text", x = 3, y = 610, label = "**",
           size = 6, color = "#22292F")+
  labs(x=NULL,y=NULL)+
  theme(plot.margin = unit(rep(1,4), "cm"))

举报

相关推荐

0 条评论