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

geom_boxplot() + scale_y_log10() bug #1020

Closed
ra81 opened this issue Oct 13, 2014 · 2 comments
Closed

geom_boxplot() + scale_y_log10() bug #1020

ra81 opened this issue Oct 13, 2014 · 2 comments

Comments

@ra81
Copy link

@ra81 ra81 commented Oct 13, 2014

This bug cost me a full day of working.

Some sample of working code

abc <- adply(matrix(rnorm(100, mean = 20, sd = 5), ncol = 5), 2, quantile, c(0, .25, .5, .75, 1))
abc$X1  <- NULL
abc$X1  <- c(1:5)
abc[6, ]  <- c(10, 18, 20, 25, 1000, 6)

# working code
b <- ggplot(abc, aes(group=X1, x = X1, ymin = `0%`, lower = `25%`, middle = `50%`, upper = `75%`, ymax = `100%`))
 b + geom_boxplot(stat = "identity", aes(fill=X1)) + coord_trans(y="log10")

This all ok. Picture is ok.
image

# broken code
b <- ggplot(abc, aes(group=X1, x = X1, ymin = `0%`, lower = `25%`, middle = `50%`, upper = `75%`, ymax = `100%`))
d <- b + geom_boxplot(stat = "identity") + scale_y_log10()

ggplot makes ranges of y axe as c(0.8490745, 3.1024250).
max value from abc is 1000 = 10^3.
y range upper bound = 10^3 + small margin. So it is log scale.
BUT when data is plotted ggplot uses absolute values of abc data not log values.
So we have wrong picture
image

Problem like this was discussed here
#274
http://stackoverflow.com/questions/9502003/ggplot-scale-y-log10-issue

@hadley
Copy link
Member

@hadley hadley commented Jul 23, 2015

Here's a simpler reproducible example:

library(plyr)
df <- data.frame(
  x = c("a", "b"),
  y1 = c(10, 10),
  y2 = c(15, 18),
  y3 = c(20, 20),
  y4 = c(22, 25),
  y5 = c(30, 1000)
)

ggplot(df, aes(x = x, ymin = y1, lower = y2, middle = y3, upper = y4, ymax = y5)) + 
  geom_boxplot(stat = "identity") + 
  scale_y_log10()

@hadley
Copy link
Member

@hadley hadley commented Jul 23, 2015

Oh hmmm, it's because lower, middle and upper aren't transformed by the scale (while ymin and ymax are). This isn't usually a problem because the stat operates on the transformed values, so you'll only see this with stat identity and a transformed y axis.

@hadley hadley closed this in 0eef89c Jul 23, 2015
@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.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants