論文
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、生物信息學入門學習資料及自己的學習筆記!
微信公衆號好像又有改動,如果沒有將這個公衆號設爲星標的話,會經常錯過公衆號的推文,個人建議將 小明的數據分析筆記本 公衆號添加星標,添加方法是