tags:

views:

176

answers:

1

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?

+4  A: 

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

All the code to generate this example is available at the site.

Alternatively, look ggplot's stat_spoke for a simple widget: alt text

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.

Alex Brown
Thanks for the answer! I removed that link because I think that you're right. More generally, unless I'm missing something, it doesn't seem like the faces() function, nor stat_spoke really address my need. faces() only shows faces...you can't alter the image. And stat_spoke doesn't allow you change the image either. But grImport looks very promising! Thanks!
griffin