-
Notifications
You must be signed in to change notification settings - Fork 2.1k
strange interaction of geom_raster and scale_{x,y}_continuous #3539
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
Comments
Could you please run your example through the reprex package and repost here? https://reprex.tidyverse.org/articles/articles/magic-reprex.html |
Here it is. library(ggplot2)
## Setup simple grid.
dat = expand.grid(x = seq(-2, 2, by = 1), y = seq(-2, 2, by = 1))
dat$val <- (1:nrow(dat))/nrow(dat)
## Case A: This plots fine without scale_{x,y}_continuous.
ggplot() + geom_raster(data = dat, aes(x = x, y = y, fill = val)) + geom_hline(yintercept = 0) + geom_vline(xintercept = 0) ## Case B: This plots fine too with limits set to be larger than extent of data grid.
ggplot() + geom_raster(data = dat, aes(x = x, y = y, fill = val)) + geom_hline(yintercept = 0) + geom_vline(xintercept = 0) + scale_x_continuous(limits = c(-3.5, 3.5)) + scale_y_continuous(limits = c(-3.5,3.5)) ## Case C: y limits are now more restricted than data limits and don't align with the data grid.
## Scaling in y direction is now distorted.
## Note that the center of the middle grid box should be at (0,0) where the horizontal and vertical lines intersect.
ggplot() + geom_raster(data = dat, aes(x = x, y = y, fill = val)) + geom_hline(yintercept = 0) + geom_vline(xintercept = 0) + scale_x_continuous(limits = c(-2.5, 2.5)) + scale_y_continuous(limits = c(-2,2.5)) Created on 2019-09-23 by the reprex package (v0.3.0) |
This was a bug - thanks for reporting. Just an FYI, you'd probably want to zoom using the |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
If one applies scale_{x,y}_continuous to a raster plot but sets the x- or y-axis limits to be smaller than the extent of the data grid, the resulting plotting of the raster cells is distorted, with the cells shrunk in the dimension where the limit is set "too" small.
Here's info on my setup:
The text was updated successfully, but these errors were encountered: