update:
GGAlly was updated again and the hack in this answer also doesn’t work anymore, but finally there’s a non-hack solution: given
scales <- scale_colour_brewer(type = 'qual') %+% scale_fill_brewer(type = 'qual')
you can do (in a hopefully future-proof way)
for (row in seq_len(ps$nrow))
for (col in seq_len(ps$ncol))
ps[row, col] <- ps[row, col] + scales
old way
The hack in the other answer does not work anymore, so let’s hack a new one!
The internal structure of a ggpairs
object is the dataset and a list of strings:
> dta <- data.frame(a=1:6, b=7:12, c=c('f', 'g'))
> ps <- ggpairs(dta, 1:2, colour = 'c')
> str(ps)
List of 10
$ data :'data.frame': 2 obs. of 3 variables:
..$ a: int [1:2] 1 2
..$ b: int [1:2] 3 4
..$ c: int [1:2] 5 6
$ columns : int [1:3] 1 2 3
$ plots :List of 9
..$ : chr "ggally_densityDiag(ggally_data, ggplot2::aes(x = a, colour = c))"
..$ : chr "ggally_cor(ggally_data, ggplot2::aes(x = b, y = a, colour = c))"
[...]
$ gg : NULL
- attr(*, "class")= chr [1:2] "gg" "ggpairs"
> ps
In order to modify the plot, the respective strings in the plot object need to be modified to include the additional command. For this, we use deparse(substitute(argument))
to get a string containing the code the user passed, and append it to every plot call:
add_to_plots <- function(pairs, modification) {
str <- deparse(substitute(modification))
pairs$plots <- lapply(pairs$plots, function(s) paste(s, '+', str))
pairs
}
> add_to_plots(ps, scale_colour_brewer(type = 'qual'))