Pangenome analysis provides insight into the evolution of the orange subfamily and a key gene for citric acid accumulation in citrus fruits
https://www.nature.com/articles/s41588-023-01516-6
论文中提供了部分图的原始数据,我们可以利用论文中提供的原始数据试着复现一下论文中的图
今天的推文我们试着复现一下论文中的figure5a
image.png
一个簇状的堆积柱形图
R语言的ggplot2没有现成的函数可以做簇状的堆积柱形图,我这里的思路是按照单一堆积柱形图的方式来做,赋予间断的横坐标,让出图效果看起来比较像簇状的堆积柱形图,接下来试试这个思路是否可行。
整理成这种格式
image.png
library(readxl)
library(tidyverse)
dat<-read_excel("2024.data/20240109/41588_2023_1516_MOESM9_ESM.xlsx",
sheet = "Sheet1",
col_names = FALSE)
dat
colnames(dat)<-paste0("X",1:4)
dat %>%
mutate(X4=factor(X4,levels = c("ratio of down-relulated genes",
"ratio of up-relulated genes",
"ratio of None-differentially expressed genes"))) -> dat
library(ggplot2)
dat
ggplot(data=dat,aes(x=X1,y=X3))+
geom_bar(aes(fill=X4),stat = "identity",
position = "fill")+
theme_bw(base_size = 15)+
theme(panel.grid = element_blank(),
panel.border = element_blank(),
axis.line = element_line(),
legend.position = "top",
legend.title = element_blank())+
guides(fill=guide_legend(ncol = 1))+
scale_x_continuous(breaks = c(1,2,3,5,6,7,9,10,11,13,14,15),
labels = rep(c("D","I","N"),4))+
scale_y_continuous(expand = expansion(mult = c(0,0)),
breaks = c(0,0.5,1),
labels = c(0,50,100))+
labs(x=NULL,y="Percentage (%)")+
scale_fill_manual(values = c("#f47720","#459943","#bdc3d2"))-> p1
p1
data.frame(x=c(2,6,10,14),
y=1,
label=c("Leaf","Fruit","Seed","Embryo")) %>%
ggplot(aes(x=x,y=y))+
geom_text(aes(label=label),
hjust=0.5)+
theme_void()+
scale_x_continuous(limits = c(1,15)) -> p2
library(patchwork)
p1+p2+
plot_layout(ncol = 1,heights = c(10,1))
image.png
最终的出图效果
这里相当于是4组柱子,第一组的横坐标为1,2,3;第二组的横坐标是5,6,7。组和组之间加2,这样就有了间隔,就做成了簇状柱形图的效果
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有