在可视化图表制作过程中,颜色是可视化要素中的一个重要要素,颜色的搭配影响着图表的整体效果,对于非专业人士,如何为自己的图表选择合适的颜色方案?R语言及扩展包提供了很多的颜色方案可供我们选择。
1. R语言内置颜色方案(调色板)可参考以下内容:
R colors [Full List, Color Converter and Color Picker] | R CHARTShttps://r-charts.com/colors/
2. 颜色方案(调色板)相关R包 2.1 离散型调色板2.1.1 ggsci包
2.1.2 ggthemes包
2.1.3 RColorBrewer包
可参考以下内容:
R Color Palettes [497 continuous and discrete palettes] | R CHARTShttps://r-charts.com/color-palettes/#discrete
2.2 连续型调色板可参考以下内容:
R Color Palettes [497 continuous and discrete palettes] | R CHARTSA collection of 497 ready to use palettes from 16 popular R packages divided into continuous (30 samples), discrete and dynamic paletteshttps://r-charts.com/color-palettes/#continuous
3. 功能强大的paletteer包 3.1 基本函数#---------------------------------------------------------
# 1-安装和加载R包
install.packages("paletteer")
library(paletteer)
#---------------------------------------------------------
# 2-查看调色板具体颜色
paletteer_c("scico::berlin", 10)
paletteer_d("nord::frost")
paletteer_d("wesanderson::Royal1", 4)
paletteer_d("Redmonder::dPBIPuOr", 10, type = "continuous")
#---------------------------------------------------------
# 3-使用方法
# palette:调色板名称的字符串,格式必须是packagename::palettename
# direction:取值为1或-1,为-1则逆转调色板的颜色
# 离散型调色板
scale_color_paletteer_d(palette, direction = 1, dynamic = FALSE, ...)
scale_fill_paletteer_d(palette, direction = 1, dynamic = FALSE, ...)
# 连续型调色板
scale_color_paletteer_c(palette, direction = 1, ...)
scale_fill_paletteer_c(palette, direction = 1, ...)
scale_color_paletteer_binned(palette, direction = 1, ...)
scale_fill_paletteer_binned(palette, direction = 1, ...)
3.2 应用举例
3.2.1 离散型调色板使用举例
base_d +
scale_fill_paletteer_d("ggsci::default_nejm")
3.2.2 连续型调色板使用举例
base_c +
scale_color_paletteer_c("ggthemes::Red-Gold")
主要参考了如下内容:
paletteer包:拥有2100多个调色板! - 云+社区 - 腾讯云ggplot2是目前主流的绘图R包,有着丰富的扩展包。今天来推荐一个极其强大的配色R包——paletteer包。据R包作者介绍,这个包收集了52个R包的2100...https://cloud.tencent.com/developer/article/1839444



