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

I'm confusing about width(height) argument in geom_jitter() #1775

Closed
kimchpekr opened this Issue Sep 24, 2016 · 6 comments

Comments

Projects
None yet
3 participants
@kimchpekr

kimchpekr commented Sep 24, 2016

"width(height)" argument in geom_jitter() is described as belows.

width

Amount of vertical and horizontal jitter. The jitter is added in both positive and negative directions, so the total spread is twice the value specified here. If omitted, defaults to 40% of the resolution of the data: this means the jitter values will occupy 80% of the implied bins.

So, I expected geom_jitter() and geom_jitter(width = 0.4) will produce same plot and "width = 0.4" spreads points across a range "base ± resolution * 0.4". but the results are not.

> p <- ggplot(mtcars, aes(gear, mpg))
> p + geom_jitter()  ## jitter range is 3 ± 0.4

default

> p + geom_jitter(width = 0.4) ## jitter range is narrow than 3 ± 0.4

width 0 4

I'm confusing about width argument and how can i calculate a jitter range.

I expect like belows but the result doesn't

geom_jitter(width = 0.2) will spread points across a range [2.8 ~ 3.2] : 3 ± 0.2
geom_jitter(width = 0.4) will spread points across a range [2.6 ~ 3.4] : 3 ± 0.4
geom_jitter(width = 0.6) will spread points across a range [2.4 ~ 3.6] : 3 ± 0.6

but, geom_point(aes(x = jitter(gear, amount = 0.2)) produce a plot what i expected.
geom_point jitter

Please, give me some hints...

@has2k1

This comment has been minimized.

Contributor

has2k1 commented Sep 24, 2016

That is clearly a bug. I think the width is being treated as a substitute for the resolution, if that is the case then the effective amount is 0.4 * 0.4 = 0.16

@kimchpekr

This comment has been minimized.

kimchpekr commented Sep 25, 2016

@has2k1 Thanks for comment.

data resolution at "gear = 3" is 1, so amount should be calculated 1 * 0.4 = 0.4 instead of 0.4 * 0.4 = 0.16

> resolution(mtcars$gear[mtcars$gear == 3])
[1] 1

but you right.
geom_jitter(width = 0.4) spreads points across a range you calculated 3±0.16 like below.
width 0 16

I'm still confusing....

@has2k1

This comment has been minimized.

Contributor

has2k1 commented Sep 25, 2016

I've since looked at the code and I'll submit a PR that fixes it.

@kimchpekr

This comment has been minimized.

kimchpekr commented Sep 25, 2016

@has2k1
I'm looking forward to it.

has2k1 added a commit to has2k1/ggplot2 that referenced this issue Sep 25, 2016

Fix jitter width and jitter height
The problem was the %||% operator accepts single tokens and so
care (bracketing as required) must be taken avoid miscalculations.

Some other places in the code-base had it right.

Fixes tidyverse#1775

@hadley hadley closed this in #1777 Sep 27, 2016

hadley added a commit that referenced this issue Sep 27, 2016

Fix jitter width and jitter height (#1777)
The problem was the %||% operator accepts single tokens and so
care (bracketing as required) must be taken avoid miscalculations.

Some other places in the code-base had it right.

Fixes #1775
@svenhalvorson

This comment has been minimized.

svenhalvorson commented Apr 13, 2017

I'm having a hard time knowing what this means:
'If omitted, defaults to 40% of the resolution of the data: this means the jitter values will occupy 80% of the implied bins.'

You're saying that the range of values that point could be mapped to is 3 +/- (resolution) * 0.4 so how is resolution determined?

@has2k1

This comment has been minimized.

Contributor

has2k1 commented Apr 13, 2017

@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018

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