Changing base colour in GGally::ggpairs in R?

75 Views Asked by At

How do you change the base colour in the ggpairs() function of the GGAlly library?

I want ONE arbitrary color for ALL the plots given by ggpairs(). Is there no simple way to achieve this?

I found answers about colouring based on some covariate in the data, e g using ggplot2::aes() in the arguments of ggpairs. I can manage to get it to use what I assume is the first colour in the default palette by ggpairs2::aes(color = "AnyThingSeemsToWorkHere"). But I just want an arbitrary colour, say purple, instead of the grey you get by default.

EDIT: I found a way by doing

ggpairs(x, mapping = ggplot2::aes(colour = "AnythingSeemsToWorksHere")) + 
  scale_fill_manual(values = c("purple")) + 
  scale_color_manual(values = c("purple"))

Does the job, but I'm not a fan of mapping the colour to a non-existent covariate like what I've done above, so I still wonder whether there is some more basic or elegant way of doing this.

1

There are 1 best solutions below

0
On BEST ANSWER

After a look at the docs and the examples I think there is no easy way to change the defaults. Basically, the defaults are inherited from ggplot2. However, besides the option to map a constant on the color aes, GGally provides the wrap_ family of functions which could be used to set or change the default arguments.

Here is a basic example using wrap() to set the color building on the default example from ggpairs:

library(GGally)
#> Loading required package: ggplot2
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2

data(flea)

ggpairs(flea,
  columns = 2:4,
  lower = list(continuous = wrap("points", color = "purple")),
  diag = list(continuous = wrap("densityDiag", color = "purple")),
  upper = list(continuous = wrap("cor", color = "purple"))
)