[圖片上傳失敗...(image-3ed7ef-1654227300997)]
今天我們復(fù)現(xiàn)一幅2022年3月發(fā)表在Cell
上的箱線圖
半醉。
Title:Tissue-resident FOLR2+ macrophages associate with CD8+ T cell infiltration in human breast cancer
之前復(fù)現(xiàn)過的箱線圖:
- 跟著 Cell 學(xué)作圖 | 3.箱線圖+散點(diǎn)+差異顯著性檢驗(yàn)
- 跟著Nat Commun學(xué)作圖 | 1.批量箱線圖+散點(diǎn)+差異分析
- 跟著Nat Commun學(xué)作圖 | 4.配對(duì)箱線圖+差異分析
- R實(shí)戰(zhàn) | 對(duì)稱云雨圖 + 箱線圖 + 配對(duì)散點(diǎn) + 誤差棒圖 +均值連線
- 跟著Nature學(xué)作圖 | 質(zhì)控箱線圖
22
[圖片上傳失敗...(image-2301f1-1654227300997)]
讀圖
本期箱線圖亮點(diǎn):
- 加上了亞組的比較
- 組間和組內(nèi)背景不同
結(jié)果展示
[圖片上傳失敗...(image-2ab642-1654227300997)]
示例數(shù)據(jù)和代碼領(lǐng)取
詳見:https://mp.weixin.qq.com/s/O6Yx-dFac-ycUUNj_bzM8w
繪制
# 導(dǎo)入數(shù)據(jù)
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
# 這里將"Mild","Severe","Critical" 三組合并為 symptomatic組
# 并對(duì)數(shù)據(jù)進(jìn)行復(fù)制并合并
library(tidyverse)
plot_data <- data.frame(FOXO3 = bar_mat$FOXO3,
group = bar_mat$sam)
plot_data2 <- plot_data %>% filter(group != 'Asymptomatic')
plot_data2$group = 'Symptomatic'
plot_data = rbind(plot_data,plot_data2)
head(plot_data)
# 設(shè)置分組因子水平
plot_data$group<-factor(plot_data$group,
levels=c("Symptomatic","Asymptomatic","Mild","Severe","Critical"))
library(RColorBrewer)
library(ggpubr)
library(ggplot2)
color <-c("#f06c61","#6b7eb9","#f06c61","#f06c61","#f06c61")
# 自行設(shè)置差異比較分組
my_comparisons <- list(c("Symptomatic","Asymptomatic"))
range(bar_mat$FOXO3)
p <- ggplot(plot_data,aes(x = group, y = FOXO3, color = group)) +
geom_rect(xmin = 0.4, xmax = 2.5,
ymin = -Inf, ymax = Inf,
fill ='#d2dbdf',
inherit.aes = F)+
geom_jitter(alpha = 0.6)+
geom_boxplot(alpha = 0.5) +
scale_color_manual(values = color)+
# 先算一下顯著性差異斋日,再手動(dòng)添加
#geom_signif(comparisons = my_comparisons,
# test = "t.test",
# map_signif_level = T)+
annotate("text", x = 1.5, y = 10.5, label ="***",size = 4)+
theme_bw() +
xlab("") +
ylab("Gene Expression (log2 TPM)")+
theme(panel.grid=element_blank(),
legend.position = "none",
axis.text.x = element_text(angle=90, hjust=1, vjust=.5))
p1 <- p +
coord_cartesian(clip = 'off',ylim = c(4,10.6))+ #在非圖形區(qū)域繪圖,且要定好y軸范圍
theme(plot.margin = margin(0.5,0.5,1.5,0.5,'cm'))+ #自定義圖片上左下右的邊框?qū)挾? annotate('segment',x=3,xend=5,y=2.8,yend=2.8,color='black',cex=.4)+
annotate('text',x=4,y=2.7,label='subtype',size=4,color='black')
p1
ggsave("p1.pdf",p1,width = 2.5,height = 6)
[圖片上傳失敗...(image-1c0938-1654227300997)]
往期內(nèi)容
- (免費(fèi)教程+代碼領(lǐng)取)|跟著Cell學(xué)作圖系列合集
- Q&A | 如何在論文中畫出漂亮的插圖?
- 跟著 Cell 學(xué)作圖 | 桑葚圖(ggalluvial)
- R實(shí)戰(zhàn) | Lasso回歸模型建立及變量篩選
- 跟著 NC 學(xué)作圖 | 互作網(wǎng)絡(luò)圖進(jìn)階(蛋白+富集通路)(Cytoscape)
- R實(shí)戰(zhàn) | 給聚類加個(gè)圈圈(ggunchull)
- R實(shí)戰(zhàn) | NGS數(shù)據(jù)時(shí)間序列分析(maSigPro)
[圖片上傳失敗...(image-2ce8dc-1654227300997)]