ggplot alpha级别在填充和点的边界上显示不同 [英] ggplot alpha levels appear different on fill and border of points

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

问题描述



我发现圆点比他们的个体有更透明的填充边框,以便边框明显比填充明亮(我在黑色背景上绘制浅色圆圈)。

效果是它们看起来像是戒指,而不是半透明的圆圈。



<$ (数据帧)(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',color ='black'))
pre>

我不确定它为什么这样做,所以为什么会发生这种情况的信息会很好。

可能的解决方案是制作边框并填充相同的透明度,或者使边框100%透明(将边框设置为背景颜色将会破坏点重叠时的视觉效果)。我不确定如何做到这一点。



*下面讨论后添加的编辑*



在RStudio查看器或保存的PNG中查看图时会出现此问题。它在查看保存的PDF时不会显示。但是,我的真实数据集很大,矢量图形在绘制大量点时效率很低,所以我会喜欢另一种解决方案!

解决方案

<改变笔划为0似乎有希望的结果:

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


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

The effect is that they look like rings rather than semi-transparent circles.

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.

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.

* Edits added after discussions below *

The issue appears when viewing the plot in the RStudio viewer or a saved PNG. It does not appear when viewing a saved PDF. However, my real dataset is large and vector graphics are inefficient at plotting large numbers of points, so I would love an alternative solution!

解决方案

Changing stroke to 0 seems to have hte desired result:

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

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

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