r - R 将颜色转换为柔和的颜色
问题描述
我有一个手动设计的调色板pal
,用于使用ggplot2
pal <- c("red","red1","red2","red3","grey","darkgreen","skyblue","blue","magenta","magenta4","yellow","orange","pink","pink","black")
我想将这些颜色转换为柔和的颜色(即 HSV 颜色空间中的高值和低饱和度)
有没有简单的方法可以自动做到这一点?
我pastel.colors
从RPMG
包中找到了,但是,这个函数不会转换给定的颜色。
解决方案
由于我不是色彩专家,您可以尝试以下作为起点。这个想法是基于我在某处发现的一个陈述,即柔和的颜色 1)在 HSV 颜色空间中具有高值和低到中等饱和度,或者 2)需要一些亮度值。hcl
所以我将颜色的名称转换为通过col2rgb
&输入的色调rgb2hsv
。
a <-c("red","red1","red2","red3","grey","darkgreen","skyblue","blue","magenta","magenta4","yellow","orange","pink","pink","black")
par(mfrow=c(3,1))
barplot(seq_along(a), col=a, main="original")
# transform to rgb
a1 <- col2rgb(a)
# transform to HSV space
a2 <- rgb2hsv(a1)
# you can try different scaling values e.g. between 0.3 - 0.6
n <- 0.4
barplot(seq_along(a), col=hsv(a2[1,], a2[2,]*n, a2[3,]), main="Pastel_hsv")
# calculate hue for HCl
hue <- a2["h",]*360
# create color with suitable chroma and luminance to get pastel color
a3 <- hcl(hue, 35, 85)
barplot(seq_along(a), col=a3, main="Pastel_hcl")
推荐阅读
- sql - 将 SQL 转换为 MariaDB 语句
- ruby-on-rails - Wicked_PDF 链接到 pdf 的索引页
- sql - 如何从 Oracle 12c 访问 Tableau 元数据 API(使用 SSO Azure 身份验证)
- python - 如何根据父 id 响应子对象?
- c++ - 如何在 main 函数中打印数字?
- codeigniter - 实体保存到数据库错误的日期格式codeigniter 4
- python - 从 Django 的过滤器中选择一个字段
- kubernetes - 是否可以跨 Kubernetes 命名空间设置存储资源配额?
- javascript - 在手风琴 React Native 中显示获取数据
- sql - 如何获取子记录的父母、祖父母等及其本身以及 SQL 中与根的距离