如何计算具有给定透明度的重叠点的Alpha?

时间:2019-04-16 16:31:39

标签: r scatter-plot

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

编辑的MWE和答案

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) ) )

1 个答案:

答案 0 :(得分: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