tags:

views:

92

answers:

1

Is it possible to plot a matrix of scatter plots with ggplot2, using ggplot's nice features like mapping additional factors to color, shape etc. and adding smoother?

I am thinking about something similar to pairs().

+3  A: 

Yup it is. Just take a look at facets / faceting. This should do the job if I understood you correctly.

use something like:

 yourplotobject +facet_grid(variable~variable)

here's a similar thread with some examples, plus you might also want to try plotmatrix:

  library(ggplot2)
  data(mtcars)
  plotmatrix(mtcars[,1:3])

to me mpg (first column in mtcars) should not be a factor. I haven't checked it, but there's no reason why it should be one. However I get a scatter plot :)

HTH

ran2
I could not get faceting to work on this problem, it seems it requires factors on the right hand side of the formula.. Or could you give me a minimal example?
Karsten W.
`plotmatrix` is what I was looking for. Thanks a lot!
Karsten W.