栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > R语言

R语言(ggplot)实用图表——颜色方案设置(编辑中……)

R语言 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

R语言(ggplot)实用图表——颜色方案设置(编辑中……)

在可视化图表制作过程中,颜色是可视化要素中的一个重要要素,颜色的搭配影响着图表的整体效果,对于非专业人士,如何为自己的图表选择合适的颜色方案?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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/855679.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号