論文
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
大部分 作圖的數(shù)據(jù)都有躺孝,可以試著用論文中提供的數(shù)據(jù)復(fù)現(xiàn)一下論文中的圖
論文中figure2和figure3中有很多種柱形圖窘拯,爭(zhēng)取把每個(gè)種類的柱形圖都復(fù)現(xiàn)一下
加載作圖用到的R包
library(readxl)
library(tidyverse)
library(ggplot2)
首先是最普通的柱形圖
figure3m
示例數(shù)據(jù)集如下
作圖代碼
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))
更多的時(shí)候會(huì)對(duì)數(shù)值進(jìn)行排序,從小到大泉懦,或者從大到小
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對(duì)調(diào)位置就行祠斧,如果數(shù)據(jù)集里的數(shù)據(jù)有正有負(fù),那么柱子呈現(xiàn)的就是既有朝上的拱礁,又有朝下的
比如這個(gè)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")
今天的推文就介紹這么多琢锋,明天繼續(xù)
示例數(shù)據(jù)和代碼可以給推文點(diǎn)贊,然后點(diǎn)擊在看呢灶,最后留言獲取
歡迎大家關(guān)注我的公眾號(hào)
小明的數(shù)據(jù)分析筆記本
小明的數(shù)據(jù)分析筆記本 公眾號(hào) 主要分享:1吴超、R語(yǔ)言和python做數(shù)據(jù)分析和數(shù)據(jù)可視化的簡(jiǎn)單小例子;2鸯乃、園藝植物相關(guān)轉(zhuǎn)錄組學(xué)鲸阻、基因組學(xué)、群體遺傳學(xué)文獻(xiàn)閱讀筆記缨睡;3鸟悴、生物信息學(xué)入門學(xué)習(xí)資料及自己的學(xué)習(xí)筆記!
微信公眾號(hào)好像又有改動(dòng)奖年,如果沒有將這個(gè)公眾號(hào)設(shè)為星標(biāo)的話细诸,會(huì)經(jīng)常錯(cuò)過(guò)公眾號(hào)的推文,個(gè)人建議將 小明的數(shù)據(jù)分析筆記本 公眾號(hào)添加星標(biāo)陋守,添加方法是