How to change the color palette for GGally :: ggpairs?

This is the same question as the Custom color palette in R and ggpairs, or is there a way to change the color palette for GGally :: ggpairs using ggplot?

just that the solutions there no longer work.


I also want to change the color palette, but is there a way to change the color palette for GGally :: ggpairs using ggplot? does not work any more. What to do?

MWE:

library(GGally)
library(ggplot2)
data(diamonds, package="ggplot2")
diamonds.samp <- diamonds[sample(1:dim(diamonds)[1],200),]
ggpairs(
  diamonds.samp[,1:2],
  mapping = ggplot2::aes(color = cut),
  upper = list(continuous = wrap("density", alpha = 0.5), combo = "box"),
  lower = list(continuous = wrap("points", alpha = 0.3), combo = wrap("dot", alpha = 0.4)),
  diag = list(continuous = wrap("densityDiag")),
  title = "Diamonds"
)

enter image description here

I'd like to add

scale_colour_manual(values=c('red','blue','green','red','blue'))

(obviously this is just dummy code) and get something like (I didn't draw all the dots):

enter image description here

+4
source share
1 answer

ggmatrix scale_, .

library(GGally)
library(ggplot2)
data(diamonds, package="ggplot2")
diamonds.samp <- diamonds[sample(1:dim(diamonds)[1],200),]

p <- ggpairs(
  diamonds.samp[,1:2],
  mapping = ggplot2::aes(color = cut),
  upper = list(continuous = wrap("density", alpha = 0.5), combo = "box"),
  lower = list(continuous = wrap("points", alpha = 0.3), combo = wrap("dot", alpha = 0.4)),
  diag = list(continuous = wrap("densityDiag")),
  title = "Diamonds"
)

,

for(i in 1:p$nrow) {
  for(j in 1:p$ncol){
    p[i,j] <- p[i,j] + 
        scale_fill_manual(values=c("red", "blue", "green", "yellow", "black")) +
        scale_color_manual(values=c("red", "blue", "green", "yellow", "black"))  
  }
}

p

enter image description here

+6

Source: https://habr.com/ru/post/1623898/


All Articles