5

Consider the following:

library(ggplot2)

df = data.frame(x = rep(0,9), y = rep(0,9), alp = c(1:8/20,1))
ggplot(df) + 
  geom_point(aes(x, y, alpha=alp), size = 20, col = 'red') + 
  theme_minimal() + facet_wrap(~ alp) + guides(alpha = F)

enter image description here

As you can see there are feint outlines. It makes overlaying many low-transparency points look a bit like frogspawn. Is this just a Mac thing? Any idea how to remove it?

Sandy Muspratt
  • 31,719
  • 12
  • 116
  • 122
geotheory
  • 22,624
  • 29
  • 119
  • 196
  • Are you talking about the very faint border of the point itself or are you talking about the underline of the background underneath the semi-transparent point? – Nick Becker Jun 28 '16 at 20:23

2 Answers2

8

The default point shape for ggplot2 is pch = 19. It's not one of those points where the colour of its border and its inside can be controlled separately; for instance, in the following, fill = 'black' has no effect.

library(ggplot2)

df = data.frame(x =runif(1000), y = runif(1000))

p = ggplot(df) + 
geom_point(aes(x, y), alpha = .1, size = 5, fill = 'black', colour = 'red') +                                        
  theme_bw() 
p

enter image description here

Yet the point does have a boundary line. The line's width can be changed with stroke; as follows:

p = ggplot(df) + 
geom_point(aes(x, y), stroke = 2, alpha = .1, size = 5, fill = 'black', colour = 'red') +                                        
  theme_bw() 
p

enter image description here

Unfortunately, setting stroke to zero will not remove the boundary line; it seems there is a lower limit.

To remove the boundary line, use one of the shapes that has a border that can be manipulated; for instance, shape = 21. Set its "fill" to red and its "colour" to transparent.

p = ggplot(df) + 
geom_point(aes(x, y), shape = 21, alpha = .1, size = 5, fill = 'red', colour = 'transparent') +                                      
  theme_bw() 
p

enter image description here

Sandy Muspratt
  • 31,719
  • 12
  • 116
  • 122
  • Whether the boundary vanishes when `stroke` is set to zero also depends on how you print the plot object: for example, when using `grDevices::svg()` to output an `svg`, the boundary disappears with `stroke = 0`. (I checked that with chromium; with SVG's appearance might also depend on your viewer.) – jarauh Jan 23 '18 at 11:55
  • Also, if yo use `grDevices::png()` with `type = "cairo"`, the boundary disappears. – jarauh Jan 23 '18 at 11:57
1

see::geom_point2 draws points without this border.

library(ggplot2)
library(see)

df = data.frame(x = rep(0,9), y = rep(0,9), alp = c(1:8/20,1))

ggplot(df) + 
  geom_point2(aes(x, y, alpha=alp), size = 20, col = 'red') + 
  theme_minimal() + facet_wrap(~ alp) + guides(alpha = F)

Created on 2020-05-14 by the reprex package (v0.3.0)

tjebo
  • 21,977
  • 7
  • 58
  • 94