Buggy default jittering values #572

Closed
huftis opened this Issue Jun 3, 2012 · 2 comments

Comments

Projects
None yet
2 participants
Contributor

huftis commented Jun 3, 2012

The way the default amount of jittering is calculated in ggplot2 (0.9.1) seems buggy, or at least sub-optimal. Here’s a simple example:

library(ggplot2)

n = 100
vals = seq(1, 500, 50)
x = sample(vals, n, replace=TRUE)
y = sample(vals, n, replace=TRUE)

qplot(x, y, geom="jitter")

Even though the actual resolution in the data is 50, the points drawn are almost overlapping. Compare this to the same code but with vals = seq(0, 500, 50).

The reason is the calculations in position-jitter.r:

if (is.null(.$width)) .$width <- resolution(data$x) * 0.4
if (is.null(.$height)) .$height <- resolution(data$y) * 0.4

If you add zero=FALSE to the two resolution() functions, it will work as expected.

Collaborator

wch commented Jun 5, 2012

Would you like to submit a pull request for this? Some instructions on getting started here:
https://github.com/hadley/ggplot2/wiki/Developing-ggplot2-using-github

If not, no problem.

Contributor

huftis commented Jun 7, 2012

OK. I’ll try to submit a pull request. (Might be a few days before I get time to do it.)

wch closed this in 5cce66c Jul 5, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment