ggprism学习

作者: Zee_李海海 | 来源:发表于2021-04-23 15:50 被阅读0次

    ggprism学习

    ggprism包提供了各种主题、调色板和其他有用的函数来定制ggplot,并为它们提供GraphPad Prism外观。

    install ggprism

    install.packages("ggprism")
    

    或者

    remotes::install_github("csdaw/ggprism")
    

    Example

    library(ggplot2)
    library(ggprism)
    tg<-ToothGrowth
    tg$dose <- as.factor(tg$dose)
    
    base <- ggplot(tg, aes(x = dose, y = len)) + 
      geom_violin(aes(colour = dose, fill = dose), trim = FALSE) + 
      geom_boxplot(aes(fill = dose), width = 0.2, colour = "black") + 
      scale_y_continuous(limits = c(-5, 40))
    base
    
    Figure.png
    p_vals <- tibble::tribble(
      ~group1, ~group2, ~p.adj,   ~y.position,
      "0.5",   "1",     8.80e-14, 35,
      "0.5",   "2",     1.27e-7,  39
    )
    base + 
      scale_color_prism("floral") +   #可以设置“candy_bright”
      scale_fill_prism("floral") + 
      guides(y = "prism_offset_minor") + 
      theme_prism(base_size = 16) + 
      theme(legend.position = "none") +  #可以调整legend的位置
      add_pvalue(p_vals, label = "p = {p.adj}", tip.length = 0, label.size = 4)
    
    Figure01.png

    https://csdaw.github.io/ggprism/articles/web-only/ex2-wings.html

    image1.png
    https://csdaw.github.io/ggprism/articles/web-only/ex1-dose.html
    image2.png
    可以参考上述链接去实现该图。

    附加

    base <- ggplot(mpg, aes(x = as.factor(cyl), y = hwy)) +
    geom_jitter(width = 0.2) +
    theme(axis.line = element_line(colour = "black"))+scale_x_discrete(guide = guide_prism_bracket(width = 0.12, outside = FALSE)) +
    theme(axis.line.x = element_line(colour = "red"),
    axis.ticks.x = element_line(colour = "blue"),
    axis.text.x = element_text(colour = "green"))
    pp<-base +labs(x=" ",y="hwy")+theme(axis.text.y =element_text (color="black"),panel.background = element_blank())
    
    Rplot.png

    随心所欲的画

    相关文章

      网友评论

        本文标题:ggprism学习

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