I’m creating geographic maps with raster files as background. For better display I want to flip some of them sidewards (i.e. so that north points to the left, instead of up). This means that I have to reverse the x-axis (in addition to flipping x and y), because otherwise the data are displayed wrongly (mirrored).
It works with geom_tile, but of course this is very slow, especially when doing facets.
So, I want to use annotation_raster. This works fine as well, but only until I reverse the x-axis. Then it is not displayed any more.
In addition and I suspect that this may be related: swiching xmin and xmax values doesn’t seem to have any effect. Always displays with xmin=min(xmin,xmax) and xmax=max(xmin,xmax).
library(ggplot2) ## v0.9.0
## works
qplot(mpg, wt, data = mtcars) + annotation_raster(rainbow, xmin=15, xmax=20, ymin=3, ymax=4)
## swiching xmin and xmax, doesn't affect plotting
qplot(mpg, wt, data = mtcars) + annotation_raster(rainbow, xmin=20, xmax=15, ymin=3, ymax=4)
## doesn't work
qplot(mpg, wt, data = mtcars) + annotation_raster(rainbow, xmin=15, xmax=20, ymin=3, ymax=4) + scale_x_reverse()
I’d appreciate any ideas.
Cheers
Kohske kindly posted a work-around on the ggplot help list, which solved this problem by using negative coordinates for annotate_raster: