在发表科研论文的过程中,科研绘图是必不可少的,一张好看的图形会是文章很大的加分项。
为了便于使用,本系列文章介绍的所有绘图都已收录到了 sciRplot 项目中,获取方式:
本期绘图预览:

1. 导入包
我们首先导入本期绘图用到的 R 包:
library(ggplot2)
2. 准备数据
接下来我们导入绘图用到的数据,在 sciRplot 中给大家提供了测试数据:
data <- sciRplot_data
3. 准备配色
颜色的选择往往是一件让人特别纠结的事情,这里我们直接使用 sciRcolor 来设置配色:
colors <- sciRcolor::pal_scircolor(37)[1:4]
sciRcolor 是为了 R 语言科研绘图开发的配色工具,包含了 100 种常用配色,详细信息见:
4. 绘制图形
接下来我们通过下面的代码来绘制图形:
p <- ggplot(data, aes(x=price, group=cut, fill=cut)) + geom_density(adjust=1.5, alpha=0.8) + labs(x="Value", y="Density") + guides(fill=guide_legend("Type")) + theme_classic(base_size = 25) + theme(panel.grid.major.y = element_line(), legend.position = "top", legend.key.size = unit(24,"pt")) + scale_fill_manual(values = rev(c("#5470c6","#91cc75","#fac858","#ee6666")))p
5. 保存图形
最后我们保存绘制的图形:
ggsave("save/density-group.png", p, width = 8, height = 6, dpi = 300)
sciRplot 介绍
为了解决 R 语言中科研绘图的问题,我推出了 sciRplot 项目。
sciRplot 项目包含了以下内容:
① 100 种绘图代码,按照图形类型进行分类,包含 60 种基础绘图 和 40 种进阶绘图

② 配备一站式 html文档 ,包含测试数据 ,代码一键复制 ,交互式阅读提高用户体验
