R可视化:dotplot图美化

作者: 生信学习者2 | 来源:发表于2020-12-03 10:54 被阅读0次

    相比boxplot图而言,dotplot能更好展示数据分布情况,记录下美化dotplot的经历。更多知识分享请到 https://zouhua.top/

    加载包

    library(dplyr)
    library(tibble)
    library(ggplot2)
    
    grp <- c("setosa", "versicolor")
    grp.col <- c("#2D6BB4", "#EE2B2B")
    

    导入数据

    dat <- iris %>% dplyr::filter(Species!="virginica") %>%
      mutate(Species=factor(Species, levels = grp))
    

    可视化

    ggplot(dat, aes(x=Species, y=Sepal.Length))+
        # dotplot 
        geom_dotplot(aes(color=Species, fill=Species), 
                     binaxis='y', stackdir='center', dotsize = .7)+
        # errorbar 
        stat_summary(fun.data=mean_sdl, fun.args = list(mult=1), 
            geom="errorbar", width=0.1, size=1) +
        # median line : crossbar  
        stat_summary(fun=median, geom="crossbar", color="black", size=.4, width=.4)+
        labs(x="")+
        scale_y_continuous(breaks = seq(3, 7, 0.5),
                           limits = c(3, 8),
                           expand = c(0, 0))+
        scale_fill_manual(values = grp.col)+
        scale_color_manual(values = grp.col)+
        guides(fill=F, color=F, shape=F)+
        # significant levels 
        annotate("segment", x = 1, xend = 2, y = 7.4, yend = 7.4, color = "black", size=1)+
        annotate("text", x = 1.5, y = 7.8, color = "black", size=6, label = "p<0.05")+  
        theme_classic()+
        theme(axis.title.y = element_text(face = 'bold',color = 'black',size = 14),
              axis.title.x = element_text(face = 'bold',color = 'black',size = 14,
                                          vjust = -1.2),
              axis.text.y = element_text(face = 'bold',color = 'black',size = 10),
              axis.text.x = element_text(face = 'bold',color = 'black',size = 12),
              axis.line = element_line(color = "black", size = 1),
              panel.grid = element_blank())
    

    参考

    1. errorbar guide

    参考文章如引起任何侵权问题,可以与我联系,谢谢。

    相关文章

      网友评论

        本文标题:R可视化:dotplot图美化

        本文链接:https://www.haomeiwen.com/subject/xoqmwktx.html