论文
Single-cell profiling of vascular endothelial cells reveals progressive organ-specific vulnerabilities during obesity
https://www.nature.com/articles/s42255-022-00674-x#Sec58
s42255-022-00674-x.pdf
https://github.com/Osynchronika/sc_EC_obesity_atlas
大部分 作图的数据都有,可以试着用论文中提供的数据复现一下论文中的图
今天的推文重复一下论文中的Figure1e 柱形图 和 Figure1f的下三角热图
Figure1e的数据论文中是提供的,格式如下
这是3个柱形图的数据,需要我们手动整理成作图格式
柱形图的作图代码
df02<-read_excel("data/20230207/42255_2022_674_MOESM3_ESM.xlsx",
sheet = "Sheet1")
df02
df02$x<-factor(df02$x,levels = df02$x)
pe1<-ggplot()+
geom_col(data=df02,aes(x=x,y=y),
fill="red",color="black")+
theme_classic()+
scale_y_continuous(expand = expansion(mult=c(0,0)),
limits = c(0,120),
breaks = seq(0,120,20))+
labs(x=NULL,y="Number of DEGs",title="Art")+
theme(plot.title = element_text(hjust=0.5,face="bold"))
df03<-read_excel("data/20230207/42255_2022_674_MOESM3_ESM.xlsx",
sheet = "Sheet2")
df03
df03$x<-factor(df03$x,levels = df03$x)
pe2<-ggplot()+
geom_col(data=df03,aes(x=x,y=y),
fill="#46b198",color="black")+
theme_classic()+
scale_y_continuous(expand = expansion(mult=c(0,0)),
limits = c(0,900),
breaks = seq(0,900,300))+
labs(x=NULL,y="Number of DEGs",title="Cap")+
theme(plot.title = element_text(hjust=0.5,face="bold"))
df04<-read_excel("data/20230207/42255_2022_674_MOESM3_ESM.xlsx",
sheet = "Sheet3")
df04
df04$x<-factor(df04$x,levels = df04$x)
pe3<-ggplot()+
geom_col(data=df04,aes(x=x,y=y),
fill="#4472c4",color="black")+
theme_classic()+
scale_y_continuous(expand = expansion(mult=c(0,0)),
limits = c(0,350),
breaks = seq(0,350,50))+
labs(x=NULL,y="Number of DEGs",title="Ven")+
theme(plot.title = element_text(hjust=0.5,face="bold"))
三个柱形图的代码基本一样
下三角相关系数热图
这个论文中没有提供数据,我手动整理下来了格式如下
作图代码
library(readxl)
library(ggplot2)
library(tidyverse)
library(paletteer)
library(latex2exp)
df<-read_excel("data/20230207/figure1f.xlsx")
x_axis<-c('Brain','Heart','Lungs','Kidney','Liver','Vis AT')
y_axis<-c('Sc AT','Vis AT','Liver','Kidney','Lungs','Heart')
table(df$var1)
table(df$var2)
df<-df %>%
mutate(var1=factor(var1,levels = x_axis),
var2=factor(var2,levels = y_axis))
txt.df<-data.frame(x=1:7,
y=7:1,
label=c('Brain','Heart','Lungs','Kidney','Liver','Vis AT','Sc AT'))
p1<-ggplot(data=df,aes(x=var1,y=var2))+
geom_tile(aes(fill=value),
color="black")+
geom_text(aes(label=value))+
geom_text(data=txt.df,
aes(x=x,y=y,label=label))+
#scale_x_discrete(expand = expansion(mult = c(0,0)))+
#scale_y_discrete(expand = expansion(mult = c(0,0)))+
theme_bw()+
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank(),
panel.border = element_blank(),
legend.position = "left",
axis.title = element_blank())+
coord_cartesian(xlim = c(0,8),y=c(0,7))+
scale_fill_gradient2(low="blue",
mid="white",
high="red",
breaks=c(-0.11,0,0.17),
name=TeX(r"(\textit{r} value)"),
midpoint=0)+
guides(fill=guide_colorbar(barheight = 10,
ticks.colour = "black"))
p1
怎么把图例做成和论文中的一样我暂时想不到了,ggplot2这个这个图例好像只能是最小值和最大值,比如现在最大值是0.17,我先让图例映射到1,这个好像实现不了
做三个一样的,然后拼图
p1+
labs(title="Art")+
theme(plot.title = element_text(hjust=0.5,
face="bold",
size=20)) -> pA
p1+
labs(title="Cap")+
theme(plot.title = element_text(hjust=0.5,
face="bold",
size=20),
legend.position = "none") -> pB
p1+
labs(title="Ven")+
theme(plot.title = element_text(hjust=0.5,
face="bold",
size=20),
legend.position = "none") ->pC
library(patchwork)
pA+pB+pC
然后将柱形图和热图拼到一起
(pe1+pe2+pe3)/(pA+pB+pC)
示例数据和代码可以给推文点赞,然后点击在看,最后留言获取
欢迎大家关注我的公众号
小明的数据分析笔记本
小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!