8

I am using ggpairs to make a pairs plot, but I only want to display the lower triangle. I can make the diagonal and upper triangle blank, but cannot make them go, which leaves an empty row and an empty column which I don't want.

Any suggestions?

library("GGally")
ggpairs(iris[, 1:4], 
        lower  = list(continuous = "points"),
        upper  = list(continuous = "blank"),
        diag  = list(continuous = "blankDiag")
        )

enter image description here

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
  • We might be able to mess with the design and intent of the package to contort the chart to your specs, but why not simply consider relevant data to include on the diagonal? – Pierre L Mar 07 '17 at 18:01
  • @PierreLafortune that would still leave the upper triangle which Richard doesn't want. – Gavin Simpson Mar 07 '17 at 18:05
  • I'm using ggpairs to plot the ccf between the variables, but made the question more general. I could show the acf on the diagonal, but the x & y scales will be different. – Richard Telford Mar 07 '17 at 18:07

1 Answers1

12

The ggpairs object can be edited. The bulk of the object is list of plots. The unwanted plots can be removed from this list and the other elements of the ggpairs object modified to match.

Here is a function that will do this

gpairs_lower <- function(g){
  g$plots <- g$plots[-(1:g$nrow)]
  g$yAxisLabels <- g$yAxisLabels[-1]
  g$nrow <- g$nrow -1

  g$plots <- g$plots[-(seq(g$ncol, length(g$plots), by = g$ncol))]
  g$xAxisLabels <- g$xAxisLabels[-g$ncol]
  g$ncol <- g$ncol - 1

  g
}

library("GGally")
g <- ggpairs(iris[, 1:4], 
             lower  = list(continuous = "points"),
             upper  = list(continuous = "blank"),
             diag  = list(continuous = "blankDiag")
     )

gpairs_lower(g)

enter image description here

Richard Telford
  • 9,558
  • 6
  • 38
  • 51