Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot alpha levels appear different on fill and border of points (ringing artefact)

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.

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.

like image 681
conor Avatar asked May 23 '16 02:05

conor


2 Answers

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

enter image description here

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

enter image description here

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

enter image description here

like image 92
Tom Wenseleers Avatar answered Oct 24 '22 14:10

Tom Wenseleers


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'))
like image 25
IRTFM Avatar answered Oct 24 '22 15:10

IRTFM