Skip to content

Plotting using image files

3 messages · Mike Saunders, Henrik Bengtsson, Romain Francois

#
Mike Saunders wrote:
I don't think this is possible using the default graphics engine in R, 
but here is another solution using ImageMagick 
(http://www.imagemagick.org/) calls from R.  I once needed something 
similar to highlight certain cities on a Swedish map given their 
longitute/latitude coordinates.  The map was given as bitmap image. 
Given a few reference citites with known longitute/latitude and pixel 
coordinates I used a quick-and-dirty 2d-loess to get a 
longitute/latitude-to-pixel coordinate mapping.  This way I could find 
the pixel coordinates for new citites and then I used ImageMagick to add 
colorful discs in the original bitmap image.  The result is as shown on 
http://www.maths.lth.se/kovalevsky/skolor/.  It is quite easy to write 
wrapper functions in R that calls ImageMagick via system() calls.  My 
code is in http://www.maths.lth.se/kovalevsky/skolor/updatemap.R, but 
please don't ask me to explain how it works, because I don't have the 
time available for that. Basically, ImageMagick's 'convert' command 
provide command line options to add discs ("circles"), lines etc in 
different colors to existing images.  Make sure to set a pen color 
before drawing.  I think it allows you to "draw" using other bitmap 
image too.  My R code generates a convert call string which is called at 
the end.

Hope this helps a bit

Henrik Bengtsson
#
Le 23.08.2005 14:52, Mike Saunders a ??crit :
Hello Mike,

Maybe you can try using the pixmap package, something like this :

require(pixmap)
logo <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1])
x <- rnorm(10)
y <- rnorm(10,sd=.4)+x
plot(x,y, type="n")
for(i in 1:10){       
                  u <- runif(1)/10 + .1
                  addlogo(logo, x[i]+c(-u,u), y[i]+c(-u,u), asp=1)
}
# points(x,y, pch="+")

All you have to de then is having your images in ppm format. I think 
gimp will do it for you.
There is also a few tools in netpbm (only on linux i think).


Romain