求Nature期刊风格R语言ggplot2箱线图实现代码
实现Nature风格箱线图的R代码方案
我准备发表论文,需要把R语言绘制的箱线图调整成符合期刊要求的美观样式,尤其喜欢Nature期刊的箱线图风格。以下是我当前的绘图代码,但生成的图不符合发表要求:
Elongation_İmage <- ggplot(PE_plot1, aes(x = Pa, y = EI, fill = as.factor(Risk_Group))) + geom_boxplot(width = 0.7, alpha = 0.8) + scale_y_continuous(name = "Elongation Index (EI)", labels = label_number(accuracy = 0.01)) + # Continuous variable label scale_x_discrete(name = "Shear Stress", labels = c("0,3", "0,53", "0,95", "1,69", "3", "5,33", "9,49", "16,87", "30")) + scale_fill_manual(values = c("#4271AE", "#FF5A5F"), labels = c("Low Risk", "High Risk")) + theme_bw() + theme(axis.text.x = element_text(colour="grey20", size = 12, angle = 45, hjust = 1), axis.text.y = element_text(colour="grey20", size = 12, vjust=0.4), axis.title = element_text(size = 14), legend.title = element_blank(), legend.position = "top", legend.text = element_text(size = 12))
修改后的Nature风格箱线图代码
library(ggplot2) library(scales) Elongation_İmage <- ggplot(PE_plot1, aes(x = Pa, y = EI, fill = as.factor(Risk_Group))) + # 优化箱线结构:黑色轮廓、加粗中线、调整箱体宽度 geom_boxplot(width = 0.6, alpha = 0.7, colour = "black", outlier.size = 1.5, median.colour = "black", median.size = 1.2) + # 保留原Y轴精度设置 scale_y_continuous(name = "Elongation Index (EI)", labels = label_number(accuracy = 0.01)) + # X轴标签替换为英文小数点格式(符合国际期刊规范) scale_x_discrete(name = "Shear Stress", labels = c("0.3", "0.53", "0.95", "1.69", "3", "5.33", "9.49", "16.87", "30")) + # 替换为Nature常用的低饱和度配色 scale_fill_manual(values = c("#2c3e50", "#e74c3c"), labels = c("Low Risk", "High Risk")) + # 使用经典无网格主题,贴合Nature极简风格 theme_classic() + # 精细化主题设置,匹配期刊排版要求 theme( axis.text.x = element_text(family = "Arial", colour = "black", size = 10, angle = 45, hjust = 1), axis.text.y = element_text(family = "Arial", colour = "black", size = 10), axis.title.x = element_text(family = "Arial", size = 12, face = "bold", margin = margin(t = 10)), axis.title.y = element_text(family = "Arial", size = 12, face = "bold", margin = margin(r = 10)), axis.line = element_line(colour = "black", size = 0.8), legend.title = element_blank(), legend.position = "top", legend.text = element_text(family = "Arial", size = 10), legend.key.size = unit(0.8, "cm"), panel.background = element_blank(), plot.background = element_blank() ) # 导出高分辨率图像(符合期刊300dpi要求) ggsave("Nature_style_boxplot.png", Elongation_İmage, dpi = 300, width = 8, height = 6, units = "in")
关键调整说明
- 主题切换:用
theme_classic()替代theme_bw(),移除背景网格,实现Nature的留白极简设计 - 箱线样式:加粗中线、设置黑色轮廓线,让箱体结构更突出;调整异常点大小,避免干扰整体视觉
- 配色优化:替换为低饱和度的沉稳色系,符合学术期刊的严谨风格
- 字体规范:统一使用
Arial无衬线字体(多数SCI期刊要求),调整标题和文本的大小、粗细,保证可读性 - 细节打磨:调整坐标轴标题边距、线条粗细,移除多余背景元素,让画面更干净
- 输出设置:添加
ggsave导出300dpi的高清图像,满足期刊的图像质量要求
内容的提问来源于stack exchange,提问作者Muhammed Edib Mokresh
相关产品推荐
相关产品推荐

