# 跟着Nature Metabolism学作图:R语言ggplot2各种各样柱形图(1)

## 论文

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

## 加载作图用到的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



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")

## 直接点击 设为星标 就可以了

|
7月前
|

1083 0
|
7月前
|

115 0
|
10月前
|

103 0
|
10月前
|

181 0
|
10月前
|

92 0
|
10月前
R语言ggplot2做表格，很好看
R语言ggplot2做表格，很好看
73 0
|
10月前
|

61 0
|