论文
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
大部分 作图的数据都有,可以试着用论文中提供的数据复现一下论文中的图
论文中figure2和figure3中有很多种柱形图,争取把每个种类的柱形图都复现一下,之前的推文已经出过一期关于柱形图的推文,今天的推文继续柱形图相关
figure4c2 普通柱形图添加误差线和显著性标记
论文中提供的数据如下
需要我们手动整理成如下格式
作图代码
library(readxl)
library(tidyverse)
library(ggplot2)
library(plotrix)
fig4c2.df<-read_excel("data/20230207/ggplot2barplot.xlsx",
sheet = "fig4c2")
fig4c2.df
fig4c2.df %>%
rowwise() %>%
mutate(mean_value=mean(c_across(rep01:rep03)),
sde_value=std.error(c_across(rep01:rep03)),
x=factor(x,levels = x)) -> fig4c2.df01
ggplot(data=fig4c2.df01,aes(x=x,y=mean_value))+
geom_errorbar(aes(ymin=mean_value-sde_value,
ymax=mean_value+sde_value),
width=0.2)+
geom_col(aes(fill=x),alpha=0.5,color="black")+
geom_jitter(data=fig4c2.df %>% pivot_longer(!x),
aes(x=x,y=value,fill=x),size=5,
shape=21,
stroke=0.3,
color="gray")+
scale_fill_manual(values = c("#094cc3","#f68a15","#008c00"))+
theme_classic()+
scale_y_continuous(expand = expansion(mult=c(0,0)),
limits = c(0,45))+
annotate(geom = "segment",x=1,xend = 2,y=43,yend=43,size=2,color="red")+
annotate(geom = "segment",x=1,xend = 1,y=43,yend=35,size=2,color="red")+
annotate(geom = "text",x=1.5,y=44,label="***",size=10,color="black")+
annotate(geom = "segment",x=1,xend = 3,y=33,yend=33,size=2,color="red")+
annotate(geom = "segment",x=1,xend = 1,y=33,yend=28,size=2,color="red")+
annotate(geom = "text",x=2.8,y=34,label="**",size=10,color="black")+
theme(legend.position = "none")+
labs(x=NULL,y=expression(paste("Percentage of body ",weight%+-%s.e.m)))
这里遇到一个问题是expression表达式中如何换行,之前好像查过,但是想不起来在哪了
在来个figure2q
论文中提供的数据如下
手动整理成如下格式
作图代码
library(ggh4x)
fig2q.df<-read_excel("data/20230207/ggplot2barplot.xlsx",
sheet = "fig2q")
fig2q.df
fig2q.df %>%
mutate(Replicate=factor(Replicate,levels=rev(Replicate))) %>%
rowwise() %>%
mutate(mean_value=mean(c_across(rep01:rep06)),
sde_value=std.error(c_across(rep01:rep06))) -> fig2q.df.01
ggplot(data=fig2q.df.01,aes(x=mean_value,y=Replicate))+
geom_errorbarh(aes(xmin=mean_value-sde_value,
xmax=mean_value+sde_value),
height=0.2)+
geom_col(aes(fill=Replicate),color="black")+
scale_x_continuous(expand = expansion(mult=c(0,0)),
limits = c(0,0.012),
breaks = c(0,0.006,0.012),
guide = "axis_minor",
minor_breaks = seq(0.0006,0.012,by=0.0006))+
theme_classic()+
geom_jitter(data=fig2q.df %>%
mutate(Replicate=factor(Replicate,levels=rev(Replicate))) %>%
pivot_longer(!Replicate),
aes(y=Replicate,x=value),
shape=21,stroke=.3,
color="gray",
size=5,fill="gray")+
scale_y_discrete(labels=c("MRT67307","GW6741","Vehicle","Vehicle"))+
labs(y=NULL,x="Fabp1 mRNA levels + s.e.m")+
theme(legend.position = "none",
plot.margin = unit(c(0.1,1,0.1,0.1),'cm'),
ggh4x.axis.ticks.length.minor= rel(0.5),
axis.ticks.length.x = unit(0.5,'lines'))+
scale_fill_manual(values = rev(c("#d2d2d2","#d07112","#3fab35","#ae2886"))) -> p2
ggplot()+
annotate(geom="segment",x=1,xend=1,y=1,yend=3.4,size=3,color="#cf7113")+
annotate(geom = "text",x=1,y=2,label="FA 800 uM",angle=90,vjust=-1)+
annotate(geom="segment",x=1,xend=1,y=3.6,yend=4.5,size=3,color="black")+
annotate(geom = "text",x=1,y=4,label="BSA",angle=90,vjust=-1)+
theme_void() -> p3
ggplot()+
annotate(geom="segment",x=1,xend=1,y=1,yend=3,size=3,color="red")+
annotate(geom = "text",x=1,y=2,label="P = 0.034",angle=90,vjust=1.5)+
annotate(geom="segment",x=1.5,xend=1.5,y=2,yend=3,size=3,color="red")+
annotate(geom = "text",x=1.5,y=2.5,label="P = 0.039",angle=90,vjust=1.5)+
annotate(geom="segment",x=1.25,xend=1.25,y=3,yend=4,size=3,color="red")+
annotate(geom = "text",x=1.25,y=3.5,label="P = 0.001",angle=90,vjust=1.5)+
theme_void()+xlim(1,2) -> p4
library(patchwork)
p3+p2+p4+
plot_layout(widths = c(1,8,1))
最后是将两个图组合到一起
library(patchwork)
p3+p2+p4+
plot_layout(widths = c(1,8,1)) -> p324
p1 + p324
示例数据和代码可以给推文点赞,然后点击在看,最后留言获取
欢迎大家关注我的公众号
小明的数据分析笔记本
小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!
微信公众号好像又有改动,如果没有将这个公众号设为星标的话,会经常错过公众号的推文,个人建议将 小明的数据分析笔记本 公众号添加星标,添加方法是