is there a way to change the color palette for GGally::ggpairs using ggplot?

后端 未结 3 1039
后悔当初
后悔当初 2020-12-30 03:37

I would like to change the color palette for the GGally function ggpairs. When I attempt to add ggplot commands to the ggplot returned using

3条回答
  •  粉色の甜心
    2020-12-30 04:34

    I feel like the most non-hacky way to change the palette is to modify its own graphing function since they return ggplot2 objects which can be customized freely.

    To change the density in the diagonal, just change the corresponding function, ggally_densityDiag.

    
    modified_density = function(data, mapping, ...) {
    
      ggally_densityDiag(data, mapping, ...) + scale_fill_brewer(type = "qual", palette = "Set2")
    }
    

    Then, provide the new function to ggparis function call, as below,

    
    ggpairs(iris, columns = 1:3,  aes(color = Species),
            diag = list(continuous = modified_density)) 
    

    There are upper and lower arguments that can be used for other parts of the plot as well.

提交回复
热议问题