如何用给定的透明度计算重叠点的alpha值?

问题描述 投票:0回答:1

我有一个覆盖透明点的散点图。我想显示单个点的颜色,以及5个重叠点的外观。

Editted MWE and Answer

alpha <- .2
gcol <- grey(0,alpha)
plot(1:5,rep(1,5), pch=16, col=gcol)
for(i in 2:5){ points(i:5, rep(1,5-i+1), pch=16, col=gcol) }

text(x=1:5,y=1.2,labels=paste0("alpha =? ",round(alpha^(1:5),5)))
points(x=1:5,y=rep(1.15,5), pch=16,
    col= sapply(round((1-alpha)^(1:5),5), function(g) grey(0, 1-g) ) )

text(x=1:5, y=0.8,labels=paste0("alpha =? ",round(alpha*(1:5),5)))
points(x=1:5, y=rep(0.75,5), pch=16,
    col= sapply(round(alpha*(1:5),5), function(g) grey(0, g) ) )
r scatter-plot
1个回答
0
投票

这是一种使用alphaggplot2水平为0.2的一个点与五个点可视化的方法:

library(ggplot2)

df <- data.frame(x = c(1, rep(2,5)),
                 y = c(rep(1,6)),
                 lab = c('One Point', 'Five Points', rep('',4)))

ggplot(data=df, aes(x,y, label=lab)) +
  geom_point(alpha=0.2, size=14) +
  geom_text(vjust=-2, size=8) +
  scale_x_continuous(limits = c(.5, 2.5)) +
  theme_minimal() +
  labs(y='',x='') +
  theme(
    axis.text.x = element_blank(),
    axis.text.y = element_blank(),
    axis.ticks = element_blank(),
    panel.background = element_blank(),
    panel.grid.major = element_blank(), 
    panel.grid.minor = element_blank(),
    axis.line = element_line(colour = "black"),
    panel.border = element_rect(colour = "black", fill=NA, size=5))

alpha plot

© www.soinside.com 2019 - 2024. All rights reserved.