Many thanks with your suggestion.
The example works like a charm, but when I try to read my own png file, I
end up in trouble.
In the example script (I copy and paste what I found in your link)
###########################################
library(png)
library(gridExtra)
m <- readPNG(system.file("img", "Rlogo.png", package="png"), FALSE)
w <- matrix(rgb(m[,,1],m[,,2],m[,,3], m[,,4] * 0.2), nrow=dim(m)[1]) #0.2
is alpha
qplot(1:10, rnorm(10), geom = "blank") +
annotation_custom(xmin=-Inf, ymin=-Inf, xmax=Inf, ymax=Inf,
rpatternGrob(motif=w, motif.width = unit(1, "cm"))) +
geom_point()
#############################################
m is an array having dimensions (x,y,4).
When I read my own png image
m <- readPNG("myfile.png", FALSE)
I end up with an array m whose dimensions are (x,y,3), hence the script
crashes because m[,,4] cannot be addressed.
I must be doing something trivially wrong, but I am puzzled.
Any suggestion is appreciated.
Cheers
Lorenzo