美文网首页Rggplot2
11-23-3 ggpubr绘图

11-23-3 ggpubr绘图

作者: 阿里丁丁 | 来源:发表于2021-08-27 21:43 被阅读0次

    特点:

    ggscatter(iris,x="Sepal.Length",y="Petal.Length",color="Species")
    
    p <- ggboxplot(iris, x = "Species", y = "Sepal.Length",  color = "Species", shape = "Species",  add = "jitter")
    p
    
    my_comparisons <- list( c("setosa", "versicolor"), 
                            c("setosa", "virginica"), 
                            c("versicolor", "virginica") )
    p + stat_compare_means(comparisons = my_comparisons)+ # Add pairwise comparisons p-value
      stat_compare_means(label.y = 9) 
    

    图片保存的三种办法

    1.基础包作图的保存

    pdf("iris_box_ggpubr.pdf")
    boxplot(iris[,1]~iris[,5])
    text(6.5,4, labels = 'hello')
    dev.off()

    2.ggplot系列图(包括ggpubr)通用的简便保存 ggsave

    p <- ggboxplot(iris, x = "Species", 
                   y = "Sepal.Length",
                   color = "Species", 
                   shape = "Species",
                   add = "jitter")
    ggsave(p,"iris_box_ggpubr.png")
    

    3.eoffice包 导出为ppt,全部元素都是可编辑模式

    library(eoffice)
    topptx(p,"iris_box_ggpubr.pptx")

    图片拼图patchwork包

    1. 拼图

    P1+P2

    2. 统一修改主题

    加上P1+P2&theme_bw()

    3. 收集图例

    加上+plot_layout(guides="collect")

    4. 修改布局P1/P2

    5. 加ABCE

    +plot

    用法

    library(patchwork)
    p1 = ggscatter(iris,x="Sepal.Length",
              y="Petal.Length",
              color="Species")
    
    p2 <- ggboxplot(iris, x = "Species", 
                   y = "Sepal.Length",
                   color = "Species", 
                   shape = "Species",
                   add = "jitter")
    p3 = ggplot(data = mpg, mapping = aes(x = class, y = hwy)) + 
      geom_boxplot()
    p4 = ggplot(data = diamonds) + 
      geom_bar(
        mapping = aes(x = cut, fill = cut), 
        show.legend = FALSE,
        width = 1
      )
    p1 + p2 + p3 + p4 + plot_annotation(tag_level = "A")
    p1/p2
    
    1. 代码运行却不出图:画板被占用
      dev.off()
      或者
      dev.new()

    相关文章

      网友评论

        本文标题:11-23-3 ggpubr绘图

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