3

Can I adjust the point size, alpha, font, and axis ticks in a plotmatrix?

Here is an example:

library(ggplot2)
plotmatrix(iris)

enter image description here

How can I:

  • make the points twice as big
  • set alpha = 0.5
  • have no more than 5 ticks on each axis
  • set font to 1/2 size?

I have fiddled with the mapping = aes() argument to plotmatrix as well as opts() and adding layers such as + geom_point(alpha = 0.5, size = 14), but none of these seem to do anything. I have hacked a bit of a fix to the size by writing to a large pdf (pdf(file = "foo.pdf", height = 10, width = 10)), but this provides only a limited amount of control.

Abe
  • 12,956
  • 12
  • 51
  • 72
  • 1
    Most of those things worked for me by doing the obvious thing, but most people use `ggpairs` from **GGally** for this kind of thing, I think. – joran Jul 30 '12 at 15:30
  • @joran that is a good hint, but `ggpairs(iris, alpha = 0.1, size = 0.1)` results in a small change to alpha and none to size. – Abe Jul 30 '12 at 19:01

1 Answers1

2

Pretty much all of the ggplot2 scatterplot matrix options are still fairly new and can be a bit experimental.

But the facilities in GGally do allows you to construct this kind of plot manually, though:

custom_iris <- ggpairs(iris,upper = "blank",lower = "blank",
                       title = "Custom Example")

p1 <- ggplot(iris,aes(x = Sepal.Length,y = Sepal.Width)) + 
          geom_point(size = 1,alpha = 0.3)
p2 <- ggplot(iris,aes(x = Sepal.Width,y = Sepal.Length)) + 
          geom_point()

custom_iris <- putPlot(custom_iris,p1,2,1)
custom_iris <- putPlot(custom_iris,p2,3,2)

custom_iris

enter image description here

I did that simply by directly following the last example in ?ggpairs.

joran
  • 169,992
  • 32
  • 429
  • 468
  • is it possible to set the size and alpha of all plots in the lower triangle without having to create each plot separately? I have a 12x12 matrix ... (by separately, I mean without a loop or vectorizing a custom function) – Abe Jul 31 '12 at 15:27
  • @Abe Hard to say without a reproducible example. – joran Jul 31 '12 at 16:31
  • 1
    @Abe Using this method you'll have to create each plot separately anyway, so I don't see the point. – joran Jul 31 '12 at 17:14
  • I don't quite understand. `ggpairs(iris)` produces plots all at once. Are you saying that the only to set the alpha value is to create each plot separately, or the only way to do this using the `putPlot` method is to create each plot separately? – Abe Jul 31 '12 at 17:17
  • @Abe As I noted in my answer, these plot matrix functions are still a bit rough around the edges. You noted that simply setting alpha didn't work. I suggested a work around involving constructing each plot separately, which as I demonstrated allows you to control the aesthetic in each plot the way you'd expect. – joran Jul 31 '12 at 17:24