使用 R 和 ggplot2 箱线图图例键的透明度
我正在尝试制作具有透明填充和相应图例的箱线图。使用 alpha 值进行绘图工作正常,只是图例键没有透明填充。下面的例子说明了困难:
dat <- data.frame(x=c('a', 'b', 'c'), y = runif(300), z = c('d', 'e', 'e'))
ggplot(dat) + geom_boxplot(aes(x, y, fill = z, colour = z), alpha = 0.2)
有没有办法进行填充图例键中的值也透明吗?
SessionInfo()
R version 2.14.0 (2011-10-31)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
ggplot2_0.8.9
预先感谢您提供有关此问题的任何提示。
alpha 映射起作用的示例如下
ggplot(dat) + geom_point(aes(x, y, fill = z, colour = z, shape = z), alpha = 0.2)
I am trying to make boxplots with a transparent fill and a corresponding legend. The plotting with alpha values works fine except that the legend keys do not have transparent fills. The following example illustrates the difficulty:
dat <- data.frame(x=c('a', 'b', 'c'), y = runif(300), z = c('d', 'e', 'e'))
ggplot(dat) + geom_boxplot(aes(x, y, fill = z, colour = z), alpha = 0.2)
Is there a way to make the fill values in the legend keys transparent too?
SessionInfo()
R version 2.14.0 (2011-10-31)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
ggplot2_0.8.9
Thanks in advance for any tips on this issue.
An example where the alpha mapping works is the following
ggplot(dat) + geom_point(aes(x, y, fill = z, colour = z, shape = z), alpha = 0.2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我过去使用过的解决方案是这个......它是一个巨大的黑客但有效。
我通常在制作 geom_text 图时使用它,但希望图例显示为点或块。但它也适用于这个例子。
如果哈德利正在关注这个线程,我发现自己想要一个plot=T/F选项,它的作用类似于这种情况下的图例选项。
The solution I've used in the past is this one... its a huge hack but works.
I usually use it when I'm making a geom_text plot, but want the legend to show as points or blocks. But it works for this instance too.
In case Hadley is paying attention to this thread, I've found myself wanting a plot=T/F option that works like the legend option for this situation.