I am not entirely sure if these kind of questions are allowed at SO, as I have no reproducible data at the moment.
My question is in regards to how one might go about creating a scatterplot of raster images in R. I am not familiar with any packages that allow you to do this. This is the only example I have come across so far in my search. Essentially, this is what I would like to do, however, I am wondering if it's possible for R to simply take the input data and plot the image rather than be fed coordinates in my plot area.
My end goal is to create raster image scatterplots of sports teams using their logos instead of labels. My first thought is to create a data frame including team name, X variable, Y variable, and .png image URL location.
Here is an example of what I am ultimately hoping to do. I'm not sure what program the OP uses, but obviously I would like to do something like this in R.
UPDATE
With the help of Greg Snow's suggestion, I was able to reproduce his example with my own logos.
The the
my.symbols
andms.image
functions in the TeachingDemos package are one possible starting place. There is an example on the help page forms.image
that shows how to use the R logo as the plotting symbol. Currently it only does one image at a time, so you could either start with a blank plot and loop through the set of images, or a wrapper function can be written that takes a list of images and an indicator of which to plot. Here is a first stab at a wrapper function:Then we can create a list of images with code like:
These are all variations on the logo, but for your example you could pass a vector of file names of the .png files to
lapply
to produce a similar list.Now we can run
my.symbols
like this (though obviously you will use real data rather than random numbers for the locations):And that produces a plot along the lines of your example:
Edit
For a speed up you can use
rasterImage
, here is some new code that ran in about half the time as the above (compared usingmicrobenchmark
):And here is some code using ggplot2 based on the link in the comment above, but using the list of logos:
And mainly for my curiosity, here are the timings: