Follow Nat Commun to learn to draw | 1. Batch boxplot + scatter + difference analysis

Follow Nat Commun to learn to draw | 1. Batch boxplot + scatter + difference analysis

The picture to be reproduced today is from an article in July 2021 Nature Communication, which is another cross-omics article on the new crown . Let's reproduce one of them today 箱线图.

c54246b5826b11dd31b84779b18cce82.png
Snipaste_2021-11-01_23-02-28

DOI:10.1038/s41467-021-24482-1

  • foreword

  • Sample data and preparation for plotting

    • gene expression matrix

    • Sample grouping information

    • data processing

  • draw

    • loop section

    • Merge puzzles

    • Some results show

  • data and code

  • postscript

  • Past content

foreword

747b15de29b522e5d0b9abd07592332f.png

About this type of boxplot in the previous article ( following Cell Learning | 3. Boxplot + Scatter + Significant Difference Test

Sample data and preparation for plotting

gene expression matrix

982ee81db10c644976e438cc6da5ea94.png
All_mRNA_FPKM.csv

Sample grouping information

dcae6a6e4ff6524ec48b86bc52192dfc.png
sample_index.csv

data processing

# 导入数据并添加分组信息
mRNA<-read.csv("All_mRNA_FPKM.csv",header=T,row.names=1)
exp<-log2(mRNA+1)
bar_mat<-t(exp)
anno<-read.csv("sample_index.csv",header=T,row.names=1)
anno$type2<-anno$Type
anno <- anno[rownames(bar_mat),]
bar_mat<-bar_mat[rownames(anno),]
bar_mat<-as.data.frame(bar_mat)
bar_mat$sam=anno$Type

draw

library(RColorBrewer)
library(ggpubr)
library(ggplot2)
# 因子水平
bar_mat$sam<-factor(bar_mat$sam,levels=c("Asymptomatic","Mild","Severe","Critical"))
# 颜色、分组比较设置
color <-c("#5CB85C","#337AB7","#F0AD4E","#D9534F")
my_comparisons <- list(c("Asymptomatic", "Mild"),
                       c("Asymptomatic", "Severe"),
                       c("Asymptomatic", "Critical"),
                       c("Mild", "Severe"),
                       c("Mild", "Critical"),
                       c("Severe", "Critical"))

loop section

# 提取需要循环绘制的基因名
gc <- colnames(bar_mat)
#开始批量绘制
plist<-list()
for (i in 1:length(gc)){
  bar_tmp<-bar_mat[,c(gc[i],"sam")]
  colnames(bar_tmp)<-c("Expression","sam")
  pb1<-ggboxplot(bar_tmp,
                 x="sam",
                 y="Expression",
                 color="sam",
                 fill=NULL,
                 add = "jitter",
                 bxp.errorbar.width = 0.6,
                 width = 0.4,
                 size=0.01,
                 font.label = list(size=30), 
                 palette = color)+
    theme(panel.background =element_blank())
  pb1<-pb1+theme(axis.line=element_line(colour="black"))+theme(axis.title.x = element_blank())
  pb1<-pb1+theme(axis.title.y = element_blank())+theme(axis.text.x = element_text(size = 15,angle = 45,vjust = 1,hjust = 1))
  pb1<-pb1+theme(axis.text.y = element_text(size = 15))+ggtitle(gc[i])+theme(plot.title = element_text(hjust = 0.5,size=15,face="bold"))
  pb1<-pb1+theme(legend.position = "NA")
  pb1<-pb1+stat_compare_means(method="t.test",hide.ns = F,comparisons =my_comparisons,label="p.signif")
  plist[[i]]<-pb1
}

Merge puzzles

library(cowplot)
pall<-plot_grid(plist[[1]],plist[[2]],plist[[3]],
                plist[[4]],plist[[5]],plist[[6]],
                plist[[7]],plist[[8]],plist[[9]],
                plist[[10]],plist[[11]],plist[[12]],plist[[13]],plist[[14]],
                plist[[15]],plist[[16]],plist[[17]],plist[[18]],
                plist[[19]],plist[[20]],plist[[21]],
                plist[[22]],plist[[23]],plist[[24]],
                plist[[25]],plist[[26]],ncol=5)
pall

Some results show

25694ae3ad214bb1ca4d515d9c56977e.png

data and code

It is not easy to generate electricity for love~ If you need sample data and code (of course, the text has been written in great detail), you can like & reward any amount , and add your own WeChat to send a screenshot on the homepage.

postscript

More detailed code explanations, some details of the author's original code, and the places I modified will be discussed in detail in the video tutorials that follow. Interested parties can pay attention to my station B [Bottle Notes] .

Past content

  1. Mapping with Nature | Paired Dumbbell Plot + Grouped Fitting Curve + Categorical Variable Heat Map

  2. (Free Tutorial + Code Collection)|Follow Cell to Learn Drawing Series Collection


a655ac968ac35442cf5b2d656543ecd2.png

Guess you like

Origin blog.csdn.net/weixin_45822007/article/details/121113070#comments_21106589