Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smallest points are removed from plot #1022

Closed
geotheory opened this issue Oct 16, 2014 · 5 comments
Closed

Smallest points are removed from plot #1022

geotheory opened this issue Oct 16, 2014 · 5 comments

Comments

@geotheory
Copy link

@geotheory geotheory commented Oct 16, 2014

This stackoverflow question gives detail.

The smallest points are lost from the plot when data ranges across several orders of magnitude and scale_size_area is being used, I think due to rounding to zero somewhere. The example demonstrates (look for the 10 point):

d = data.frame(x=1:4, y=rep(1,4), v=10^(1:4))
ggplot(d, aes(x, y, size=v)) + geom_point(alpha=.5) + geom_text(aes(label = v), size=8, col='red') +
scale_size_area(max_size = 500) + theme(legend.position = "none")

Mostly not a problem, but can be for some plots - this map of commuter patterns loses points in neighbouring cities (white labels show where points should be).

@geotheory
Copy link
Author

@geotheory geotheory commented Oct 17, 2014

Wonder if it has something to do with the waiver function, called by continuous_scale in scale_size_area..

@hadley
Copy link
Member

@hadley hadley commented Oct 17, 2014

I suspect its rounding by the graphics system - ie the point is 0.45 pixels wide so gets rounded down to 0

@geotheory
Copy link
Author

@geotheory geotheory commented Oct 17, 2014

Possibly, but counting against a rendering issue the problem reproduces in Mac and Windows. It also happens when the ‘max_size’ argument is increased experimentally to giant proportions.

@hadley
Copy link
Member

@hadley hadley commented Jun 12, 2015

Ah good point, thanks!

d <- data.frame(x = 1:4, y = rep(1, 4), v = 10 ^ (1:4))
ggplot(d, aes(x, y, size=v)) + 
  geom_point(alpha = 1/3) + 
  geom_text(aes(label = v), size = 8, col = "red") +
  scale_size_area(max_size = 500) + 
  theme(legend.position = "none") +
  xlim(0, 5)

last_plot() %+% d[1:3, ]

Looks like the rounding is happening somewhere else

@hadley
Copy link
Member

@hadley hadley commented Jul 21, 2015

Oh I bet it's this:

scale_map.continuous <- function(scale, x, limits = scale_limits(scale)) {
  x <- scale$oob(scale$rescaler(x, from = limits))

  # Points are rounded to the nearest 500th, to reduce the amount of
  # work that the scale palette must do - this is particularly important
  # for colour scales which are rather slow.  This shouldn't have any
  # perceptual impacts.
  x <- round_any(x, 1 / 500)
  uniq <- unique(x)
  pal <- scale$palette(uniq)
  scaled <- pal[match(x, uniq)]

  ifelse(!is.na(scaled), scaled, scale$na.value)
}
@hadley hadley closed this in 8434e4c Jul 21, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants