0

I'm trying to produce a specific plot using ggpairs of the GGally package with code like the following:

data(tips, package="reshape")
pm <- ggpairs(tips[,1:3], axisLabels="none")

My problem is that I can't figure out how to remove the labels "total_bill", "tip", "sex" from the sides of the plot. Is there a way of doing this?

zx8754
  • 52,746
  • 12
  • 114
  • 209
user2699676
  • 95
  • 1
  • 7

1 Answers1

1

By doing:

 data = tips[,1:3]
 pm <- ggpairs(data)
 g11<-ggally_blank() 

 for(i in 1:ncol(data)) {
     for(j in 1:ncol(data)) {
         if(i<=j) {
             pm <- putPlot(pm, g11, i, j)
         }
     }
 }

You get rid of the axisLabels from the side of the plot, and you get a 'blank' graph in the diagonal and upper triangle of the graph (as requested). In your case, the "18 columns" would be captured by ncol(data) in the loop. Does that work?

It would look like this: enter image description here

Mayou
  • 8,498
  • 16
  • 59
  • 98
  • Alas no. This is because I would then like to blank the diagonal and upper triangle of plots with something like: ggpairs(tips[,1:3], upper="blank", diag="blank") but this would leave non-empty diagonal elements – user2699676 Aug 20 '13 at 13:58
  • @user2699676 I have modified the answer to leave a blank diagonal and upper-triangle in the graph. Please look above. Does that do the trick? – Mayou Aug 20 '13 at 14:13
  • That works but I then have the problem that I'd like to do the same thing for another dataset with 18 variables. That would give me a 18x18 matrix of plots which would require 18(18+1)/2 = 171 such putPlot commands which is doable but not pretty. – user2699676 Aug 20 '13 at 14:28
  • @user2699676 Well, you could easily structure that as a loop. Please refer to my edited answer. – Mayou Aug 20 '13 at 14:40
  • There might be a more elegant way of doing a similar loop using the `apply` function. If the above isn't efficient with your dataset, you could look into replacing the nested `for loop` with `apply`. – Mayou Aug 20 '13 at 14:46
  • This seems to work for my application, so thanks Mariam. I'd still be interested to know if there's a way of turning off the labels in ggpairs through a command though if it exists or changing their style. – user2699676 Aug 20 '13 at 15:02