Re: [R] Plotting using image files

From: Henrik Bengtsson <hb_at_maths.lth.se>
Date: Tue 23 Aug 2005 - 23:41:02 EST

Mike Saunders wrote:
> This is a strange request, but I want to build a scatterplot using different image files (jpegs, gif, etc.) as the plot symbols. I have thought about setting this up using a very large layout matrix, but I thought someone might have a better approach. Furthermore, is there any way to have R paste an image file into a specific coordinate within a scatterplot?

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

> Thanks in advance,
> Mike
>
>
> Mike Saunders
> Research Assistant
> Forest Ecosystem Research Program
> Department of Forest Ecosystem Sciences
> University of Maine
> Orono, ME 04469
> 207-581-2763 (O)
> 207-581-4257 (F)
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Aug 23 23:46:42 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:44:12 EST