# 跟着Nature Communications学作图：R语言ggplot2柱形图展示GO富集分析的结果

+关注继续查看

## 论文

Chromosome-level assemblies of multiple Arabidopsis genomes reveal hotspots of rearrangements with altered evolutionary dynamics

https://www.nature.com/articles/s41467-020-14779-y

拟南芥NC_panGenome.pdf

https://github.com/schneebergerlab/AMPRIL-genomes

## 首先是读取数据

library(readxl)
dat<-read_excel("data/20230318/Source_Data.Figure5/5e/Fig5e.HOT.genes.GO.xlsx")
dat

## 最基本的柱形图

library(ggplot2)
ggplot(dat,aes(x=Term,y=Count))+
geom_col()

## 进行一些美化

library(tidyverse)

dat %>%
mutate(Term=str_replace(Term,"GO:[0-9]+~","")) %>%
arrange(desc(Count)) %>%
mutate(Term=factor(Term,levels = Term)) %>%
ggplot(aes(x=Term,y=Count))+
geom_col(aes(fill=PValue))+
theme_bw()+
theme(axis.text.x = element_text(angle = 60,hjust=1),
legend.position = c(0.9,0.4))+
scale_y_continuous(expand = expansion(mult = c(0,0)),
limits = c(0,65))+
scale_fill_gradient(low="blue",high = "red",
name=expression(italic("P-value")))+
labs(x=NULL)

fig5d<-read_delim("data/20230318/Source_Data.Figure5/5d/Fig5d.txt",
delim = "\t")
library(ggh4x)

fig5d %>%
mutate(region=factor(region,levels = c("SYN","HOR"))) -> fig5d
ggplot(data=fig5d,aes(x=high-effect-variant-percent,y=region))+
geom_boxplot(outlier.alpha = 0,
aes(fill=region),
width=0.4)+
theme_bw()+
theme(legend.position = "none",
panel.border = element_blank(),
axis.line = element_line(),
panel.grid = element_blank())+
scale_x_continuous(limits = c(0,15))+
guides(x=guide_axis_truncated(trunc_lower = 0,
trunc_upper = 15),
y=guide_axis_truncated(trunc_lower = 1,
trunc_upper = 2))+
scale_fill_manual(values = c("#2b6aa8","#f39200"))+
labs(x="Deleterious variants (%)",y=NULL)

## 最后是拼图

library(patchwork)
p2+p1+
plot_layout(widths = c(1,3))

|
4月前
|

534 0
|
4月前
|

77 0
|
7月前
|

74 0
|
7月前
|

45 0
|
7月前
|

69 0
|
7月前
|

57 0
|
7月前
|

168 0
|
7月前
|

175 0
|
7月前
|

53 0
|
7月前
|

103 0