R绘图模板——柱状图+散点图+折线图+显著性!

1、加载R包:

library(ggplot2) # Create Elegant Data Visualisations Using the Grammar of Graphics
library(reshape2) # Flexibly Reshape Data: A Reboot of the Reshape Package
library(tidyr) # Tidy Messy Data
library(dplyr) # A Grammar of Data Manipulation
library(ggsignif) # Significance Brackets for 'ggplot2'

2、加载绘图数据并进行数据处理:


#数据——ggplot自带的ToothGrowth数据
df <- ToothGrowth
df$dose <- as.factor(df$dose)
data <- df
#计算均值及标准差
df1 <- data%>% group_by(dose)%>%
  summarise(mean= mean(len), sd= sd(len))

3、绘图:

ggplot()+ 
  geom_bar(df1,mapping=aes(x=dose,y=mean), fill = "white",
           size = 1.5,color = c("#d20962","#f47721","#7ac143"),position="dodge",
           stat="identity",width = 0.6)+
  geom_errorbar(df1,mapping=aes(x = dose,ymin = mean-sd, ymax = mean+sd),
                width = 0.3,color = c("#d20962","#f47721","#7ac143"), size=1.5)+
  geom_jitter(df, mapping=aes(x=dose,y=len,fill = dose,color = dose,shape = dose),
              size = 2.5,width = 0.2,alpha=0.9)+ 
  geom_line(df1,mapping=aes(x=dose,y=mean,group=1),
            size=1,color="#00aee6")+
  geom_point(df1,mapping=aes(x=dose,y=mean),color="black",size=3,shape=8)+
  scale_color_manual(values = c("#d20962","#f47721","#7ac143"))+ 
  geom_signif(df,mapping=aes(x=dose,y=len), 
              comparisons = list(c("0.5", "1"),
                                 c("1","2"),
                                 c("0.5","2")),
              map_signif_level=T, 
              tip_length=c(0,0,0,0,0,0), 
              y_position = c(35,40,45), 
              size=1, textsize = 7, 
              test = "t.test")+
  scale_y_continuous(expand = c(0, 0), limit = c(0, 50))+
  theme_classic(base_line_size = 1)+
  theme(panel.grid=element_blank(),
        axis.text=element_text(color='black',size=13,face = "bold"),
        axis.title.y = element_text(color='black',size=15,face = "bold"),
        legend.text = element_text(color='black',size=13,face = "bold"),
        legend.title = element_blank(),
        legend.position = "none")+
  labs(x=NULL,y="Value")
R绘图模板——柱状图+散点图+折线图+显著性!

    特别申明:本文为转载文章,转载自 科研后花园,不代表贪吃的夜猫子立场,如若转载,请注明出处:https://mp.weixin.qq.com/s/OGhdZNJrvA1mK4pHE7JGaA

    (0)
    打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
    xujunzju管理者
    上一篇 2023年5月23日 08:40
    下一篇 2023年5月27日 02:05

    相关推荐

    发表回复

    登录后才能评论
    联系我们
    邮箱:
    xujunzju@gmail.com
    公众号:
    xujunzju6174
    捐赠本站
    捐赠本站
    分享本页
    返回顶部