美文网首页
分面小提琴图

分面小提琴图

作者: 一只小脑斧 | 来源:发表于2022-06-08 20:34 被阅读0次

    教程来自 https://mp.weixin.qq.com/s/Gr05DMadYnp5yLUEQ2HIoQ 感谢老俊俊哥

    数据大概长这个样子
    有三列
    group:high,low
    BIOSYNTHESIS:数值变量
    donor_tumour_stage_at_diagnosis:分期 1 2 3

    #加载包
    library(tidyverse)
    library(ggpubr)
    library(ggsci)
    library(introdataviz)
    #画图
    ################分三组
    # plot
    ggplot(df,aes(x = group,y =BIOSYNTHESIS,fill=donor_tumour_stage_at_diagnosis )) +
      # split violin分小提琴
      geom_split_violin(alpha = .5, trim = F,color = NA,width = 1) +
      # mean point加均值点
      stat_summary(fun = "mean", geom = "point",position = position_dodge(0.2)) +
      # errorbar
      stat_summary(fun.data = "mean_sd", geom = "errorbar", width = .15,
                   size = 0.3,
                   position = position_dodge(0.2)) +
      theme_bw(base_size = 16) +
      theme(axis.text.x = element_text(angle = 90,color = 'black',hjust = 1),
            legend.position = 'top') +
      scale_fill_brewer(palette = 'Set1') +
      scale_fill_jco(name = '') +
      theme(panel.grid=element_blank())+#去掉网格
      #ylim(1,8) +
      # 添加显著性标记
      stat_compare_means(aes(group=donor_tumour_stage_at_diagnosis),
                                         method = "anova",#三组
                         symnum.args=list(cutpoints = c(0, 0.001, 0.01, 0.05, 1),
                                          symbols = c("***", "**", "*", "NS")),label = "p.signif")
    
    
    three2.png

    分三个有点丑呀,,ԾㅂԾ,,

    ################分两组
    # plot
    ggplot(df,aes(x = donor_tumour_stage_at_diagnosis,y =BIOSYNTHESIS,fill=group)) +
      # split violin分小提琴
      geom_split_violin(alpha = .5, trim = F,color = NA,width = 1) +
      # mean point加均值点
      stat_summary(fun = "mean", geom = "point",position = position_dodge(0.2)) +
      # errorbar
      stat_summary(fun.data = "mean_sd", geom = "errorbar", width = .15,
                   size = 0.3,
                   position = position_dodge(0.2)) +
      theme_bw(base_size = 16) +
      theme(axis.text.x = element_text(angle = 90,color = 'black',hjust = 1),
            legend.position = 'top') +
      scale_fill_brewer(palette = 'Set1') +
      scale_fill_jco(name = '') +
      theme(panel.grid=element_blank())+#去掉网格
      #ylim(1,8) +
      # 添加显著性标记
      stat_compare_means(aes(group=group),
                         symnum.args=list(cutpoints = c(0, 0.001, 0.01, 0.05, 1),
                                          symbols = c("***", "**", "*", "NS")),label = "p.signif")
    
    paired.png

    相关文章

      网友评论

          本文标题:分面小提琴图

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