-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Vertical line and crossbar jitter being applied differently. #2941
Comments
There are two separate issues here. First, you need to set the seed if you need two library(ggplot2)
df <- structure(list(
Test = c("A", "B", "C", "D", "A", "C", "D"),
mean = c(1, 100.793684, 1, 1, 51.615601, 1, 2.456456),
sd = c(1, 2.045985, 1, 1, 4.790053, 1, 4.250668),
lower = c(2, 102.839669, 2, 2, 56.405654, 2, 6.707124),
upper = c(0, 98.747699, 0, 0, 46.825548, 0, -1.79421)),
row.names = c(NA, -7L), class = c("tbl_df", "tbl", "data.frame"))
# works fine once seed is set
ggplot(df, aes(x = Test, y = mean)) +
geom_point(aes(x= Test, y = mean),
position = position_jitter(width = 0.2, height = 0.2, seed = 123))+
geom_linerange(aes(ymin = lower, ymax = upper),
position = position_jitter(width = 0.2, height = 0.2, seed = 123)) # doesn't work because the crossbars don't get jittered correctly
ggplot(df, aes(x = Test, y = mean)) +
geom_point(aes(x= Test, y = mean),
position = position_jitter(width = 0.2, height = 0.2, seed = 123))+
geom_errorbar(aes(ymin = lower, ymax = upper),
width = 0.1,
position = position_jitter(width = 0.2, height = 0.2, seed = 123)) Created on 2018-10-15 by the reprex package (v0.2.1) |
Thanks. I always forget to set the seed, I was initially using a jitter set before the geom_ calls, but this was having the same odd errorbar problem as in the examples above. I'll look at a work-around using geom_linerange |
I have found out what the problem is. The way the jittering code is set up, it actually jitters different x or y aesthetics separately, i.e., Lines 76 to 79 in 3550772
The solution could be something like the following, though I don't particularly like it: Also, it looks like ggplot2/R/position-jitterdodge.R Lines 67 to 70 in 3550772
|
That's interesting. I have found that if I use |
Actually, ignore that - I just noticed I had changed to |
This is just quick note that the ggplot2:::aes_to_scale(c("x", "xmin", "xmax"))
#> [1] "x" "x" "x" Created on 2019-05-23 by the reprex package (v0.2.1) |
I have this issue - basically the different components of the geom_errorbar have jitter being applied to them differently. I posted this on stack-exchange and someone there seemed to think it might be a bug.
Basic data set:
Now the code I am using:
Thanks.
The text was updated successfully, but these errors were encountered: