欢迎关注R语言数据分析指南
❝本节来分享nature communications上一篇论文中的一张区域缩放条形图,作者提供了完整的代码及数据但是结果与原图相差甚远。小编进行了代码修改后可以实现原文图表绘制,个人观点,仅供参考,更多详细内容请查看论文内介绍。
论文信息
Gut microbial β-glucuronidases and their role in the microbiome-metabolite axis in colorectal cancer
Chen, J., Li, Y., Tang, S. et al. Gut microbial β-glucuronidases and their role in the microbiome-metabolite axis in colorectal cancer. Nat Commun 16, 10660 (2025). https://doi.org/10.1038/s41467-025-65679-y
论文原图
结果图
加载R包
library(tidyverse)
library(reshape2)
# install.packages("remotes")
# remotes::install_github("hughjonesd/ggmagnify") # 安装 ggmagnify包
library(ggmagnify)
library(readxl)
library(Rmisc)
数据整合
data <- read_xlsx("./00.rawdata/InVitro/17GUSformat.xlsx",sheet = 1,col_names = T) %>%
as.data.frame()
data <- data %>% reshape2::melt(by='GUS') %>%
summarySE(measurevar="value", groupvars=c("GUS","Sub"))
orderGUS <- (data %>% dplyr::group_by(GUS) %>%
dplyr::summarise(value=max(value)) %>% dplyr::arrange(desc(value)))$GUS
data$GUS <- factor(as.vector(data$GUS),levels = orderGUS)
绘制主图
p <- ggplot(data, aes(x = GUS, y = (value), fill = Sub)) +
geom_errorbar(aes(ymin = (value) - (se), ymax = (value) + (se)),
width=.5, position=position_dodge(.9)) +
geom_bar(position=position_dodge(), stat="identity") +
labs(x=NULL,y="nmol/mg protein/min") +
scale_y_continuous(expand = c(0,0)) +
scale_x_discrete(expand = c(0,0)) +
scale_fill_manual(values = c("#2F5CBF","#2CB1B3")) +
guides(fill=guide_legend(position = "inside")) +
theme(axis.text.y=element_text(color="black"),
axis.text.x = element_text(
color=c(rep("#D24A43",8),rep("#D9902E",7),rep("#3C6ECF",2)),
angle = 45,vjust=1,hjust = 1),
legend.background = element_blank(),
legend.position.inside = c(0.3,0.8),
legend.title = element_blank(),
panel.background = element_blank(),
plot.background = element_blank())
缩放图
p + coord_cartesian(clip = "off") +
# from代表原始图要进行缩放的数据区域
geom_magnify(from=c(7,17,0,210), # to缩放图所处的位置坐标
to=c(8,17,1000,5000),
# axes="xy" 表示缩放图展示坐标轴刻度
colour="black",linetype =1,linewidth = 0.3,
axes = "y",shadow = F)
关注下方公众号下回更新不迷路
❝本节介绍到此结束,最近依然有不少读者想购买小编之前写的R绘图文档,因此在附上一下购买方式及所能提供的服务具体如下:以往的交流群已经满员不在考虑建立新群,因此只会通过公众号后台发送腾讯文档链接
1.内容更新截止2025年/12月/31日结束,后期无任何更新。
2.只分享案例内容,无答疑。
3.内容只包含R语言绘图内容,无任何生信分析全套代码,有过高期望者不要买。
4.有充足时间者可以考虑继续等待,2026年会正式出版R语言绘图相关的书籍
❝若上述几点都可以接受,欢迎点击下方所付费购买此文档,购买后会通过公众号后台发送文档链接,通过在线腾讯文档分析案例清单,内附案例下载链接,案例代码文件夹支持下载到本地查看。
只分享文档查看链接,无交流群,不添加任何联系方式 购买前建议后台沟通了解。
在线目录大纲
❝通过腾讯文档在线编辑,小编可实时进行bug注解,只要保证R软件及R包版本号与案例所示一致,无须担心代码运行报错问题。在线文档内附有案例代码下载链接
html注释文档
从2025年起的除极个别案例外,其余案例图提供下方所示html注释文档非常方便查看


