gpt4 book ai didi

ggplot2 中的反向叠加 alpha 值

转载 作者:行者123 更新时间:2023-12-02 08:16:37 25 4
gpt4 key购买 nike

ggplot2 中的 alpha 值通常用于帮助在 R 中绘制重叠图。较深的颜色表示许多观测值落入的区域,而较浅的颜色表示只有少数观测值落入的区域。有可能扭转这一局面吗?那么,离群值(通常很少观察)被强调为较暗,而大多数数据(通常有很多观察)被强调为较浅?

下面是一个MWE:

myDat <- data.frame(x=rnorm(10000,0,1),y=rnorm(10000,0,1))
qplot(x=x, y=y, data=myDat, alpha=0.2)

远离中心 (0,0) 的观测值越稀少,颜色越浅。我该如何扭转呢?感谢您的任何想法。

最佳答案

您可以尝试分别为每个点设置 alpha 值,不透明度从中心进一步增加。像这样

p = 2 # adjust this parameter to set how steeply opacity ncreases with distance
d = (myDat$x^2 + myDat$y^2)^p
al = d / max(d)
ggplot(myDat, aes(x=x, y=y)) + geom_point(alpha = al)

enter image description here

关于ggplot2 中的反向叠加 alpha 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41410403/

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