问题
I'm working on a scatterplot using geom_jitter but want to set limits on the y axis (min value = 0). Is there a way to allow the points to "jitter" per usual but to tell them not to drop below y=0?
回答1:
Don't censor
the out of bounds (oob
) points (which is the default), but instead squish
to your scale, like so:
test <- data.frame(x = mtcars$mpg, y = 0)
ggplot(test, aes(x, y)) +
geom_jitter() +
scale_y_continuous(limits = c(0, 0.4), oob = scales::squish)
来源:https://stackoverflow.com/questions/48032561/keep-points-above-zero-in-geom-jitter