基于离散值的阴影颜色(更改“亮度") [英] Shade colors (change 'brightness') based on discrete values

查看:54
本文介绍了基于离散值的阴影颜色(更改“亮度")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,最好使用颜色阴影来指示离散值的级别.

It would be nice to use color shading to indicate levels of a discrete value for example.

所以代替这个:

ggplot( mpg ) + 
    geom_boxplot( 
        aes(x=manufacturer,y=hwy,fill=interaction(str_match(trans,"auto|manual")[,1],manufacturer)) 
    )

我希望每个制造商都有特定的颜色,然后将其手动"或自动"的颜色稍深一些.除了我不想为每种颜色的值指定每种颜色及其较深的阴影之外,我很高兴使用当前的调色板.

I would want to have a specific color per manufacturer, and then have it slightly darker for either of "manual" or "auto". Except I wouldn't want to specify every single color and its darker shade for the levels of my values, I'm happy to go with the current color palette.

可以使用多种相对简单的方法来调整颜色的亮度,目前我有兴趣将其连接到ggplot中.

There are multiple relatively straightforward to adjust brightness of a color, I'm interested in wiring this into ggplot at the moment.

例如,有没有可用的钩子可供我使用,以使用类似 shade 的美感?

Are there for example hooks available that I could tap into, to use something like a shade aesthetics?

推荐答案

尽管更改Alpha效果很好,但这并不是完全更改亮度",而是更改图形的透明度.

Although changing the alpha is great, it is not exactly changing the "brightness", but the transparency of the graphs.

有一个可能的解决方法,也可以使用alpha,但是要覆盖具有相同组的黑箱图.

Here a possible workaround, also using alpha, but for an overlying black box plot with the same groups.

我在第一个绘图中添加了色彩美感,以便通过 trans 将各组分开.

I added the color aesthetic to the first plot in order to separate the groups by trans.

然后您可以通过更改 scale_alpha_manual

library(tidyverse)
ggplot(mpg) +
# the ugly interaction call is to avoid weirdly coloured outlier dots. 
  geom_boxplot(aes(x = manufacturer, y = hwy, fill = manufacturer, 
                   group = interaction(manufacturer,(str_match(trans,"auto|manual"))))) +
  geom_boxplot(aes(x = manufacturer, y = hwy, alpha = str_match(trans,"auto|manual")), fill = 'black') +
  scale_alpha_manual(values = c(0.1,0.4))

reprex软件包(v0.3.0)创建于2020-01-16 sup>

Created on 2020-01-16 by the reprex package (v0.3.0)

这篇关于基于离散值的阴影颜色(更改“亮度")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆