Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set alpha and remove black outline of density plots in ggpairs

Tags:

r

ggplot2

ggally

Consider this example:

data(tips, package = "reshape")
library(GGally)
pm <- ggpairs(tips, mapping = aes(color = sex), columns = c("total_bill", "time", "tip"))
pm

enter image description here

How do I make the density plots more transparent and remove the black lines?

The GGally packages seems to have changed a lot recently and I cannot find a working solution

update

I found how to change the alpha with a custom function:

my_dens <- function(data, mapping, ..., low = "#132B43", high = "#56B1F7") {
  ggplot(data = data, mapping=mapping) +
    geom_density(..., alpha=0.7) 
}

pm <- ggpairs(tips, mapping = aes(color = sex), columns = c("total_bill", "time", "tip"),
              diag=list(continuous=my_dens))
pm

but the black line still remains.

like image 844
spore234 Avatar asked Jan 24 '16 11:01

spore234


1 Answers

thanks to @Henrik this is the solution using a custom function

my_dens <- function(data, mapping, ...) {
  ggplot(data = data, mapping=mapping) +
    geom_density(..., alpha = 0.7, color = NA) 
}

pm <- ggpairs(tips, mapping = aes(color = sex), columns = c("total_bill", "time", "tip"),
              diag = list(continuous = my_dens))
pm

enter image description here

Examples on how to customize ggpairs plots can be found in the vignette. See the "Matrix Sections" and "Plot Matrix Subsetting".

like image 190
spore234 Avatar answered Sep 16 '22 14:09

spore234