ggplot2:scale_alpha()的阈值 [英] ggplot2: Thresholds for scale_alpha()

查看:784
本文介绍了ggplot2:scale_alpha()的阈值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为颜色范围指定阈值?

Is it possible to specify thresholds for color-scales?

查看此示例:

xy <- expand.grid(x=1:20,y=1:20)
xyd <- data.frame(xy,z=runif(400),a=rowSums(xy)/40)
g <- ggplot(xyd, aes(x=x, y=y, fill=z, alpha=a)) + 
       geom_tile() + 
       scale_alpha(range=c(0,1), limits=c(0.5,1))
g


$ b b

我想要的是,a值低于0.5时,alpha值为0,因此左下半部分将不可见。显然,我可以转换原始数据,但会破坏传说。

What I want is that Values of a below 0.5 get an alpha value of 0 so that the lower left half will be invisible. Obviously I could transform the original data but that would destroy the legend.

推荐答案

阈值是工作,设置为 NA ;问题是 alpha NA 正在呈现为完全不透明度。将 na.value 设置为 0 可获得所需的结果。

The threshold is working and the values outside that threshold are set to NA; the problem is that an alpha of NA is getting rendered as full opacity. Setting the na.value on the scale to 0 gets the results you want.

ggplot(xyd, aes(x=x, y=y, fill=z, alpha=a)) + 
       geom_tile() + 
       scale_alpha(range=c(0,1), limits=c(0.5,1), na.value = 0)

这篇关于ggplot2:scale_alpha()的阈值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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