gpt4 book ai didi

r - ggplot2 中的 fiddle 图与透明体的叠加

转载 作者:行者123 更新时间:2023-12-04 12:10:01 25 4
gpt4 key购买 nike

这是我正在使用的代码:

library(ggplot2)
coco1<-rnorm(10000,0,1)
coco2<-rnorm(10000,10,5)
coco3<-rnorm(10000,20,10)
coco4<-rnorm(10000,30,20)
decile<-rbinom(10000,3,1/2)+1
coconut<-data.frame(coco1,coco2,coco3,coco4,decile)

p <- ggplot(coconut, aes(factor(decile), coco1))
p <- p + geom_violin(aes(colour = "1"), alpha = .5, size=2)
q <- p + geom_violin(aes(y = coco2, colour = "2"), alpha = .5, size=2)
q <- q + geom_violin(aes(y = coco3, colour = "3"), alpha = .5, size=2)
q <- q + geom_violin(aes(y = coco4, colour = "4"), alpha = .5, size=2)

q

生成此图像:

enter image description here

请注意 fiddle 的主体如何在您走得越远的 fiddle 层中产生透明度问题?理想情况下,我希望 body 的 alpha=0 和 body 的轮廓有 alpha=1。

最佳答案

p <- ggplot(coconut, aes(factor(decile), coco1)) + 
geom_violin(aes(colour = "1"), fill = NA, size=2) +
geom_violin(aes(y = coco2, colour = "2"), fill = NA, size=2) +
geom_violin(aes(y = coco3, colour = "3"), fill = NA, size=2) +
geom_violin(aes(y = coco4, colour = "4"), fill = NA, size=2)

p

resulting plot

关于r - ggplot2 中的 fiddle 图与透明体的叠加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35661666/

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