The RgoogleMaps package does something similar to this, you could look at the
code to see how those functions work and if they can be modified to work with
your graphic.
The general idea is to load the picture and plot it (the rimage package reads
and plots jpeg images, there are some other functions for other formats), then
work out some mapping between the coordinates in the plot and the information
that you want to add to the plot. One of the easiest ways to do this is using
the updateusr function in the TeachingDemos package (find 2 points that you can
find in the current plot/image (corners work great, or use locator) and that you
know the coordinates of in the new coordinate system, pass that info to
updateusr), then just use the points/lines/symbols function to add the
information to the background picture.
You may want to look at the animation package for the second part of your
question.
Hope this helps,
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of S?ren H?jsgaard
> Sent: Monday, June 01, 2009 4:18 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Creating a plot with an image as background
>
> I want to create a plot of positions (x(t),y(t)) of animals in a barn
> for t=1,2,... (I have in mind creating many of these, saving them as
> png's and combining them into a small movie). I have an image file
> showing the physical layout of the barn, and I would like to have that
> image as background for the plots. Can that be done in R (easily) or is
> that something I should do outside of R using e.g. ImageMagick?
> (Creating the .png's with R and then subsequently overlaying them???).
> Thanks
> S?ren
>
> ______________________________________________
> R-help at 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.