Hi
Rajarshi Guha wrote:
Hi, I have a plot and I would like to overlay a PNG image over it. I'm
using the rasterImage function to do this, but the problem I'm facing
is working out the coordinates of the upper right corner of the final
image in user coordinates.
That is I can place the image so the lower left is located at the
bottom of the y-axis and the left end of the x-axis. Since my image is
say 100px x 100px, is there a way for me to convert a 100px length
into the appropriate value in user coordinates, along the x-axis?
Are you trying to draw the image at its "native" resolution?
R should be able to scale the image using interpolation to whatever size
you want, but if you really want to try for native resolution, this
should get you close ...
# Import a raster image
library(pixmap)
logo <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1])
# Image size
l...@size
# A plot
plot(rnorm(100), rnorm(100))
# If you know the screen resolution, use that, otherwise
# the device may be telling R something close to the truth
dpi <- (par("cra")/par("cin"))[1]
usr <- par("usr")
xl <- usr[1]
yb <- usr[3]
xr <- xl + xinch(l...@size[2]/dpi)
yt <- yb + yinch(l...@size[1]/dpi)
# Image at "native" resolution
rasterImage(matrix(rgb(l...@red, l...@green, l...@blue),
nrow=l...@size[1]),
xl, yb, xr, yt)
Paul
Thanks,
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.