[R] Plotting using image files
Henrik Bengtsson
hb at maths.lth.se
Tue Aug 23 15:41:02 CEST 2005
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 at 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
>
>
More information about the R-help
mailing list