美文网首页
Violin Plot (ggpubr)

Violin Plot (ggpubr)

作者: Zee_李海海 | 来源:发表于2021-02-25 15:28 被阅读0次

    小提琴图与箱形图相似,不同之处在于它也显示了数据在不同值处的概率密度

    带有误差线的小提琴图

    library(ggpubr)
    ggviolin(data, x=, y=,
      combine = FALSE,
      merge = FALSE,
      color = "black",
      fill = "white",
      palette = NULL,
      alpha = 1,
      title = NULL,
      xlab = NULL,
      ylab = NULL,
      facet.by = NULL,
      panel.labs = NULL,
      short.panel.labs = TRUE,
      linetype = "solid",
      trim = FALSE,
      size = NULL,
      width = 1,
      draw_quantiles = NULL,
      select = NULL,
      remove = NULL,
      order = NULL,
      add = "mean_se",
      add.params =list(),
      error.plot = "pointrange",
      label = NULL,
      font.label =list(size = 11, color = "black"),
      label.select = NULL,
      repel = FALSE,
      label.rectangle = FALSE,
      position = position_dodge(0.8),
      ggtheme = theme_pubr()
      ...)
    

    Example

    library(ggpubr)
    data("ToothGrowth")
    df<-ToothGrowth
    str(df)
    'data.frame':   60 obs. of  3 variables:
     $ len : num  4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ...
     $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
     $ dose: num  0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...
    p<-ggviolin(df, x = "dose", y = "len")
    p
    
    violin.png
    # Change the plot orientation: horizontal(改变图片方向)
    p<-ggviolin(df, x = "dose", y = "len",orientation = "horiz")
    
    violin01.png
    # Add summary statistics
    # ++++++++++++++++++++++++++
    # Draw quantiles(画分位数)
    p<-ggviolin(df, "dose", "len", add = "none",draw_quantiles = 0.5)
    
    violin02.png
    # Add box plot
    p<-ggviolin(df, x = "dose", y = "len",add = "boxplot")
    
    violin03.png
    p<-ggviolin(df, x = "dose", y = "len",add = "dotplot")
    
    violin04.png
    # Add jitter points and
    # change point shape by groups ("dose")
    p<-ggviolin(df, x = "dose", y = "len",add = "jitter", shape = "dose")
    
    violin05.png
    # Add mean_sd + jittered points  
    p<-ggviolin(df, x  =  "dose", y  =  "len", add  =  c("jitter", "mean_sd"))
    
    violin06.png
    # Change error.plot to "crossbar"
    p<-ggviolin(df, x = "dose", y = "len",add = "mean_sd", error.plot = "crossbar") 
    #可视化误差线,("pointrange", "linerange", "crossbar", "errorbar", "upper_errorbar", "lower_errorbar", "upper_pointrange", "lower_pointrange", "upper_linerange", "lower_linerange")
    
    violin07.png
    # Change colors
    # +++++++++++++++++++++++++++
    # Change outline and fill colors
    p<-ggviolin(df, "dose", "len",color = "black", fill = "gray")
    
    violin08.png
    # Change outline colors by groups: dose
    # Use custom color palette and add boxplot
    p<-ggviolin(df, "dose", "len",  color = "dose",palette = c("#00AFBB", "#E7B800", "#FC4E07"),add = "boxplot")
    
    violin09.png
    # Change fill color by groups: dose
    # add boxplot with white fill color
    ggviolin(df, "dose", "len", fill  =  "dose", palette  =  c("#00AFBB", "#E7B800", "#FC4E07"), add  =  "boxplot", add.params  = list (fill  =  "white"))
    
    violin10.png
    # Plot with multiple groups  
     # fill or color box plot by a second group : "supp"  
    ggviolin(df, "dose", "len", color  =  "supp", palette  = c("#00AFBB", "#E7B800"), add  =  "boxplot")
    
    violin11.png

    参考链接:https://rpkgs.datanovia.com/ggpubr/reference/ggviolin.html
    http://www.sthda.com/english/wiki/ggplot2-violin-plot-quick-start-guide-r-software-and-data-visualization

    相关文章

      网友评论

          本文标题:Violin Plot (ggpubr)

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