Is there some way to use a specific small image as a point in a scatterplot with ggplot2. Ideally I will want to resize the images based on an variable.
Here's an example:
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(aes(size = qsec, shape = factor(cyl)))
So I basically want to know if there is a way to supply a specific image as the shape?
Here's a minimalist geom to display raster images instead of points,
(output from the ggflags package)
First, here's your answer:
To show you how to use how you might better use widgets to represent data differentiation, I refer you to the example of chernoff faces at the R graph gallery.:
alt text http://addictedtor.free.fr/graphiques/graphiques/graph_87.png
All the code to generate this example is available at the site.
Alternatively, look ggplot's stat_spoke for a simple widget: alt text http://had.co.nz/ggplot2/graphics/706b1badf6469940342f204b7bc98857.png
grImport provides a mechanism to import simple PDF images into your plot for use as points.
Now follows a critique of your example.
This is not a scatterplot. It's essentially a flowed list of ordered data points where colour is used to indicate one of the text variables, and an uninformative and redundant widget has been used to frame the data but otherwise provides no visual feedback in terms of size or shape.
It is not a good graph, because it completely fails to answer the stated question "Does Paying More Lead To Better Results", and leaves the reader to struggle draw that conclusion (and that other graph, as necessary) by themselves.
In addition, the authors have wasted the x, y axes - which could have been well used to position elements by outgoing and results, to provide a visual understanding of value-for-money. Instead they have opted to order the icons by the ratio of per head cost to average graduation rate, which is sort of useful, but doesn't answer the stated question, and fails to allow a direct visual comparison of relative ratio between colleges, or the relationship between cost and value.
As I say, in my opinion, this is a bad graph, and your readers would not be well served by having you replicate it.
There is a library called
ggimage
to do that. See an intro vignette hereYou just have to add a column to your
data.frame
with the address of the images, which can be stored on the web or locally on your computer and then you can use thegeom_image()
:ps. Note that
ggimage
depends on EBImage. So to installgginamge
I had to do this: