Follow Cell Learning | 3. Box plot + scatter + significant difference test

Follow Cell Learning | 3. Box plot + scatter + significant difference test

"Practice is the only test of truth."

"Reproduction is the best way to learn R."


DOI: 10.1016/j.cell.2020.05.032

cellThis omics article on the new crown published in 2020 contains a lot of life letter content. Today I will take you to reproduce one of them Supplemental Figure: a boxplot with scatter .

Code and sample data collection in this article: background reply " 20210416 "

2021.4.16_1

Compare common visualization methods for showing differences.

Data Format

2021.4.16_2

Note: The above data is purely fictitious and has no practical significance!

ideas

  • Boxplot + Significance Test + Scatter

Common ways to compare means:

method R implementation function describe
T-test t.test() Comparing two groups (parametric test)
Wilcoxon test wilcox.test() Comparing two groups (nonparametric test)
ANOVA aov() or anova() Comparing multiple groups (parametric test)
Kruskal-Wallis kruskal.test() Comparing multiple groups (nonparametric test)

draw

#------
title: "boxplot"
author: "MZBJ"
date: "2020/4/16"
#-----
 # 导入所需的包
library(ggplot2)
library(ggsignif)
library(ggpubr)
library(RColorBrewer)
setwd("F:/HJH/mzbj/cell")
# 导入数据
plot_data <- read.csv(file = "ABCD.csv")
#-----------------------
p<- ggplot(data=plot_data)+ 
  geom_boxplot(mapping=aes(x=group,y=Retive_Abundance,colour = group ), #箱线图
               alpha = 0.5,
               size=1.5,
               width = 0.6)+ 
  geom_jitter(mapping=aes(x=group,y=Retive_Abundance,colour = group), #散点
              alpha = 0.3,size=3)+
  scale_color_manual(limits=c("A","B","C","D"), 
                     values=c("#85B22E","#5F80B4","#E29827","#922927"))+ #颜色
  geom_signif(mapping=aes(x=group,y=Retive_Abundance), # 不同组别的显著性
              comparisons = list(c("A", "B"), # 哪些组进行比较
                                 c("A", "C"),
                                 c("A", "D"),
                                 c("B", "C"),
                                 c("B", "D"),
                                 c("C", "D")),
              map_signif_level=T, # T显示显著性,F显示p value
              tip_length=c(0,0,0,0,0,0,0,0,0,0,0,0), # 修改显著性线两端的长短
              y_position = c(40,41,42,39,38,40), # 设置显著性线的位置高度
              size=1, # 修改线的粗细
              textsize = 4, # 修改显著性标记的大小
              test = "t.test")+ # 检验的类型
  theme_classic(  # 主题设置,这个是无线条主题
    base_line_size = 1 # 坐标轴的粗细
  )+
  labs(title="White blood cell(WBC)",x="",y="Retive_Abundance")+ # 添加标题,x轴,y轴内容
  theme(plot.title = element_text(size = 15,
                                  colour = "black",
                                  hjust = 0.5),
        axis.title.y = element_text(size = 15, 
                                    # family = "myFont", 
                                    color = "black",
                                    face = "bold", 
                                    vjust = 1.9, 
                                    hjust = 0.5, 
                                    angle = 90),
        legend.title = element_text(color="black", # 修改图例的标题
                                    size=15, 
                                    face="bold"),
        legend.text = element_text(color="black", # 设置图例标签文字
                                   size = 10, 
                                   face = "bold"),
        axis.text.x = element_text(size = 13,  # 修改X轴上字体大小,
                                   color = "black", # 颜色
                                   face = "bold", #  face取值:plain普通,bold加粗,italic斜体,bold.italic斜体加粗
                                   vjust = 0.5, # 位置
                                   hjust = 0.5, 
                                   angle = 0), #角度
        axis.text.y = element_text(size = 13,  
                                   color = "black",
                                   face = "bold", 
                                   vjust = 0.5, 
                                   hjust = 0.5, 
                                   angle = 0) 
  )
p

2021.4.16_3.png

You're done!

Note: One flaw is that the y-axis is too long. But after I set the y-axis range, the difference markers are also truncated. The solution that can be thought of at present is that the AI ​​simply pulls down the Y axis.


Past content:

Follow CELL to learn to map | 1. Volcano map

Follow the Cell Science | 2. Histogram + Error Bar + Scatter + Significant Difference Test

Guess you like

Origin blog.csdn.net/weixin_45822007/article/details/115775115#comments_20860831