Turns out, this is possible! It requires looking up the source code, but the solution comes up pretty easily. We are interested in ggpairs
function, so the first step is just
ggpairs
Let's see if we can find any aes mapping to fill or colour. Indeed,
combo_aes <- addAndOverwriteAes(aes_string(x = xColName,
y = yColName, ...), section_aes)
We may hope it does what it says. Two important notes:
colour and fill aes should be contained in the ellipsis for the
ggpairs
callaes_string()
is used
Let's try this out:
ggpairs(diamonds[, 1:2], colour='cut')
Excellent, we're almost there! We just need to override the colour palette. Note that something like you propose
ggpairs(diamonds[, 1:2], colour='cut') + scale_fill_brewer(palette = "Set2")
will not work because ggpairs object is not a ggplot, so the +
notation is not directly applicable in any way. However, the simple workaround is provided here. Cross your fingers, and...
ggplot <- function(...) ggplot2::ggplot(...) + scale_fill_brewer(palette="Set2")
ggpairs(diamonds[, 1:2], colour='cut')