gpt4 book ai didi

r - 使用 R 和 ggplot2 的箱线图图例键的透明度

转载 作者:行者123 更新时间:2023-12-04 08:53:07 24 4
gpt4 key购买 nike

我正在尝试使用透明填充和相应的图例制作箱线图。除了图例键没有透明填充外,使用 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)

Boxplot with transparencies in fill, but not int the legend

有没有办法使图例键中的填充值也透明?
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)

Plot where alpha mapping works fine

最佳答案

我过去使用的解决方案是这个......它是一个巨大的黑客但有效。

dat <- data.frame(x=c('a', 'b', 'c'), y = runif(300), z = c('d', 'e', 'e'))
dummy <- dat
dummy$z <- factor(dummy$z)
dummy <- dummy[1,]
dummy[,2]<-NaN
ggplot() +
geom_boxplot(data=dat,aes(x, y, fill = z, colour = z), alpha = 0.2,legend=FALSE) +
geom_density(data=dummy,aes(x, fill = z, colour = z), alpha = 0.2)

我通常在制作 geom_text 图时使用它,但希望图例显示为点或块。但它也适用于这个实例。

如果 Hadley 正在关注这个线程,我发现自己需要一个 plot=T/F 选项,它的作用类似于这种情况下的图例选项。

关于r - 使用 R 和 ggplot2 的箱线图图例键的透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8503977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com