I'm new to ggplot2
and relatively new to R. I can make a picture appear on a plot, and I can make the y axis reverse scale, but I don't know how to do both at once. For example:
library(ggplot2)
y=c(1,2,3)
x=c(0,0,0)
d=data.frame(x=x, y=y)
#following http://stackoverflow.com/questions/9917049/inserting-an-image-to-ggplot2/9917684#9917684
library(png)
library(grid)
img <- readPNG(system.file("img", "Rlogo.png", package="png"))
g <- rasterGrob(img, interpolate=TRUE)
#these work fine - either reversing scale, or adding custom annotation
ggplot(d, aes(x, y)) + geom_point()
ggplot(d, aes(x, y)) + geom_point() + scale_y_reverse()
ggplot(d, aes(x, y)) + geom_point() + annotation_custom(g, xmin=.23, xmax=.27, ymin=1.8, ymax=2.2)
#these don't...combining both reverse scale and custom annotation
ggplot(d, aes(x, y)) + geom_point() + annotation_custom(g, xmin=.23, xmax=.27, ymin=1.8, ymax=2.2) + scale_y_reverse()
ggplot(d, aes(x, y)) + geom_point() + annotation_custom(g, xmin=.23, xmax=.27, ymin=2.2, ymax=1.8) + scale_y_reverse()
I'm sure I'm missing something pretty basic. Where should I start looking both to get my little graphic to display on a reverse scale plot, and also to understand things better under the hood?
CLARIFICATION IN RESPONSE TO COMMENTS: The example above is me trying to simplify the problem I'm having. I don't know if it matters, but I'm not merely trying to overlay some data on a static image. I actually want to place an image in a certain spot on a plot, based on the data in the plot. However, I can't seem to do that when the axis scale is reversed. And, as it turns out, I can't even put an image in an absolute position when the scale is reversed either, so that's the code example I posted.