I am working on something similar, this is the approach i would take,
- Ensure legends are set to 'TRUE' in the
ggpairs
function call Now iterate over the subplots in the plot matrix and remove the legends for each of them and just retain one of them since the densities are all plotted on the same column.
colIdx <- c(3,5,6,7) for (i in 1:length(colIdx)) { # Address only the diagonal elements # Get plot out of matrix inner <- getPlot(p, i, i); # Add any ggplot2 settings you want (blank grid here) inner <- inner + theme(panel.grid = element_blank()) + theme(axis.text.x = element_blank()) # Put it back into the matrix p <- putPlot(p, inner, i, i) for (j in 1:length(colIdx)){ if((i==1 & j==1)){ # Move legend right inner <- getPlot(p, i, j) inner <- inner + theme(legend.position=c(length(colIdx)-0.25,0.50)) p <- putPlot(p, inner, i, j) } else{ # Delete legend inner <- getPlot(p, i, j) inner <- inner + theme(legend.position="none") p <- putPlot(p, inner, i, j) } } }