39

I'm having trouble recreating a plot since I updated to ggplot version 2.0.0: It seems I can't reduce the point size as much as before, which is a problem in a plot with very many points. In the below examples, there is a reasonable difference in point size between plot1 and plot2, the point size in plot3 is at least a little bit smaller, but between plot3 and plot4 there's no difference in point size:

df <- data.frame(x=1:10, y=runif(10))
pl <- ggplot(df) +
    geom_point(aes(x,y), size=1)
ggsave("plot1.png", plot=pl, width=14, height=7, units="cm", dpi=1200 )

pl <- ggplot(df) +
    geom_point(aes(x,y), size=0.1)
ggsave("plot2.png", plot=pl, width=14, height=7, units="cm", dpi=1200 )

pl <- ggplot(df) +
geom_point(aes(x,y), size=0.01)
ggsave("plot3.png", plot=pl, width=14, height=7, units="cm", dpi=1200 )

pl <- ggplot(df) +
geom_point(aes(x,y), size=0.001)
ggsave("plot4.png", plot=pl, width=14, height=7, units="cm", dpi=1200 )

In the previous version of ggplot2 I had used a point size of 0.25 and it looked way smaller than it does now, which is why I tried to further reduce it using the new ggplot2 version. Do I miss a change in the code of the new version? Couldn't find anything in the documentation...

silkita
  • 547
  • 1
  • 5
  • 12
  • 3
    In the [ggplot 2.0.0 announcement](http://blog.rstudio.org/2015/12/21/ggplot2-2-0-0/) we find that "`geom_point()` now uses shape 19 instead of 16.". I don't know if that's the only change which have affected point appearance. – Henrik Jan 06 '16 at 17:58
  • Yes, I saw that, but couldn't find anything concerning the size – silkita Jan 06 '16 at 18:00
  • 2
    Interesting - using shape=16 yields much smaller point sizes than the new shape=19, and shape="." is actually a square and not a dot – silkita Jan 06 '16 at 18:21
  • If you're worried about having too many points that overlap, you could adjust the transparency using ```alpha```. That might be a good workaround to still see where there are areas of higher density. – Nancy Jan 06 '16 at 19:33
  • come on...I've just spent one hour trying to recreate a plot I did with the previous version of ggplot2...I'll go with shape=16... – Matteo De Felice Feb 01 '16 at 10:10

2 Answers2

35

Ok, I've found the solution. As pointed out by @henrik and @silkita now the default shape has changed from 16 to 19 in the latest ggplot2 release. And as you can see in the documentation (for example here) the shape '19' is slightly larger than '16'. But this is not the reason why "points" are larger in version 2.0.0. Looking at the ggplot2 source of geom-point.R for the latest release we can see that:

default_aes = aes(
    shape = 19, colour = "black", size = 1.5, fill = NA,
    alpha = NA, stroke = 0.5
  )

While in the previous releases it was:

default_aes <- function(.) aes(shape=16, colour="black", size=2, fill = NA, alpha = NA)

Then, to have the small point as before we should put stroke to zero. To summarise, to obtain the smallest point you should write:

geom_point(size = 0.1) # ggplot2 before 2.0.0
geom_point(size = 0.1, stroke = 0, shape = 16) # ggplot2 2.0.0

By the way, when working with smallest points there is no difference between using different shapes (a pixel remains a pixel).

UPDATE: As pointed out on Twitter by Hadley Wickham this change was explained in the release notes

Matteo De Felice
  • 1,488
  • 9
  • 23
  • 1
    Good solution. Interesting that they changed it. I would say it was maybe a regression. – Mike Wise Feb 03 '16 at 02:15
  • 3
    Except when I try it out it does not work. And the documentation you linked claims that `stroke` doesn't even work on `shape=16`. – Mike Wise Feb 26 '16 at 09:31
  • Try **size=I(1),stroke=I(0),shape=I(16)**, but I think changing the shape is not significant – meolic Sep 24 '19 at 18:07
27

Try using the shape parameter:

n <- 10000
df <- data.frame(x=1:n, y=runif(n))
pl <- ggplot(df) +
  geom_point(aes(x,y), size=1,shape=".") + labs(title="shape='.',size=1")
pl

yields:

enter image description here

while:

pl <- ggplot(df) +
  geom_point(aes(x,y), size=1) + labs(title="size=1")
pl

yields: - (and it is the same for all smaller sizes)

enter image description here

Mike Wise
  • 22,131
  • 8
  • 81
  • 104
  • Thank you, definitely better than before and a good workaround, but I need even smaller points (which I had in the previous ggplot2 version), and would like to really control the point size... – silkita Jan 06 '16 at 17:53
  • Yes, I had a similar issue. Should look and see if this is filed as a regression bug yet. – Mike Wise Jan 06 '16 at 17:55
  • 2
    Looks like this issue still hasn't been fixed more than 5 years later – scs Dec 02 '21 at 09:06