论文
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中有很多种柱形图,争取把每个种类的柱形图都复现一下
加载作图用到的R包
library(readxl)
library(tidyverse)
library(ggplot2)
首先是最普通的柱形图
figure3m
示例数据集如下
作图代码
fig3m.df<-read_excel("data/20230207/ggplot2barplot.xlsx",
sheet = "fig3m")
fig3m.df
ggplot(data=fig3m.df,aes(x=x,y=y))+
geom_col(fill="#5ab033",color="black")+
theme_classic()+
scale_y_continuous(expand = expansion(mult = c(0,0)),
limits = c(0,0.5))+
labs(x=NULL,y="log(FC)")+
theme(panel.grid.major.y = element_line(),
axis.text.x = element_text(angle=90,face="italic",
vjust=0.5,hjust=1))
更多的时候会对数值进行排序,从小到大,或者从大到小
fig3m.df %>%
arrange(y) %>%
mutate(x=factor(x,levels = x)) %>%
ggplot(aes(x=x,y=y))+
geom_col(fill="#5ab033",color="black")+
theme_classic()+
scale_y_continuous(expand = expansion(mult = c(0,0)),
limits = c(0,0.5))+
labs(x=NULL,y="log(FC)")+
theme(panel.grid.major.y = element_line(),
axis.text.x = element_text(angle=90,face="italic",
vjust=0.5,hjust=1)) -> p1
fig3m.df %>%
arrange(desc(y)) %>%
mutate(x=factor(x,levels = x)) %>%
ggplot(aes(x=x,y=y))+
geom_col(fill="#5ab033",color="black")+
theme_classic()+
scale_y_continuous(expand = expansion(mult = c(0,0)),
limits = c(0,0.5))+
labs(x=NULL,y="log(FC)")+
theme(panel.grid.major.y = element_line(),
axis.text.x = element_text(angle=90,face="italic",
vjust=0.5,hjust=1)) -> p2
p1/p2
柱形图除了水平摆放,也可以垂直摆放,我们把作图代码里的x和y对调位置就行,如果数据集里的数据有正有负,那么柱子呈现的就是既有朝上的,又有朝下的
比如这个figure r s
代码
fig3r.df<-read_excel("data/20230207/ggplot2barplot.xlsx",
sheet = "fig3r")
fig3r.df %>%
mutate(x=factor(x,levels = c("Vcam1","Pecam1","Alcam","Icam1","Gja4","Gja5","F11r"))) %>%
ggplot(aes(x,y))+
geom_col(fill="#ee7770",color="black")+
geom_text(aes(y=c(-0.01,-0.01,-0.01,-0.01,-0.01,0.01,0.01),
label=x),
angle=90,hjust=c(1,1,1,1,1,0,0),
color=c("#bf1818","#bf1818","#bf1818","#bf1818","black","black","blue"))+
theme_classic()+
theme(axis.line.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
panel.grid.major.y = element_line(),
plot.title = element_text(hjust = 0.5))+
scale_y_continuous(limits = c(-0.25,0.25),
breaks = c(-0.25,seq(-0.2,0.2,by=0.1),0.25),
expand = expansion(mult = c(0,0)),
labels = c("",seq(-0.2,0.2,by=0.1),""))+
labs(x=NULL,y="log(FC)",title = "Art")
今天的推文就介绍这么多,明天继续
示例数据和代码可以给推文点赞,然后点击在看,最后留言获取
欢迎大家关注我的公众号
小明的数据分析笔记本
小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!
微信公众号好像又有改动,如果没有将这个公众号设为星标的话,会经常错过公众号的推文,个人建议将 小明的数据分析笔记本 公众号添加星标,添加方法是