ggplot alpha级别在点的填充和边界上出现不同(振铃伪影) [英] ggplot alpha levels appear different on fill and border of points (ringing artefact)

查看:231
本文介绍了ggplot alpha级别在点的填充和边界上出现不同(振铃伪影)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ggplot绘制许多点,并且所有点的透明度值都是恒定的。

I am plotting many points using ggplot with a constant transparency value for all points.

我发现圆形点比单个点更透明边框,以便边框明显比其填充要亮(我在深色背景上绘制浅色的圆圈),即似乎有响亮的伪影。

What I find is that the circular points have a more transparent fill than their individual border, so that the borders are noticeably brighter than their fill (I'm plotting light circles on a dark background), i.e. there seems to be a ringing artefact.

<一个href = https://i.stack.imgur.com/k20kW.png rel = nofollow noreferrer>效果是它们看起来像圆环,而不是半透明的圆圈。

library(ggplot2)
set.seed(123)
data <- data.frame( x = sample(1:100,2000, replace=T), 
                    y = sample(1:100,2000, replace=T) )
ggplot(data, aes(x,y)) + 
  geom_point(alpha=0.2, color="dodgerblue", fill="dodgerblue", size=4) +
  theme(panel.background = element_rect(fill = 'black', colour = 'black'))

我不确定为什么要这么做,所以关于为什么会发生这种情况会很棒。

I'm not sure why it does this, so information as to why this occurs would be great.

可能的解决方案是使边框和填充相同的透明度,或者使边框100%透明(将边框设置为背景颜色会损坏)点重叠时的视觉效果)。我不知道该怎么做。

Possible solutions would be to make the border and fill the same transparency, or to make the border 100% transparent (setting the border to say, the background colour, would ruin the visuals when points overlap). I'm not sure how to do either of these.

推荐答案

鉴于您想要的磁盘具有恒定的颜色&不透明最简单的方法就是为我修复它,同样在RStudio图预览窗口中也只是使用选项 shape = 16

Given that you want disks with constant colour & opacity simplest thing to do that fixed it for me, also in the RStudio plot preview window is just to use option shape=16 :

data <- data.frame( x = sample(1:100,2000, replace=T), 
                y = sample(1:100,2000, replace=T) )
ggplot(d, aes(x,y)) + 
  geom_point(alpha=0.2, color="dodgerblue", size=5, shape=16) +
  theme(panel.background = element_rect(fill = 'black', colour = 'black'))

或者, shape = 21 和100%半透明填充
fill = adjustcolor( dodgerblue,alpha.f = 0)也可以:

Alternatively, shape=21 and a 100% semitransparent fill with fill=adjustcolor("dodgerblue",alpha.f=0) also works:

ggplot(data, aes(x,y)) + 
     geom_point(alpha=0.2, fill=adjustcolor("dodgerblue",alpha.f=0), size=5, shape=21) +
     theme(panel.background = element_rect(fill = 'black', colour = 'black'))

按照当前接受的答案中的建议使用 stroke = 0 似乎无法解决问题完全对我来说(振铃效果消失了一点,但不是完全消失,至少在Windows上是这样):

Using stroke=0 as suggested in the currently accepted answer doesn't seem to resolve the problem entirely for me (ringing effect goes away a little bit but not entirely, this is on Windows at least) :

ggplot(data, aes(x,y)) + 
    geom_point(alpha=0.2, colour="dodgerblue", fill="dodgerblue", stroke=0,  size=5) +
    theme(panel.background = element_rect(fill = 'black', colour = 'black'))

这篇关于ggplot alpha级别在点的填充和边界上出现不同(振铃伪影)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆