daattali / ggExtra

📊 Add marginal histograms to ggplot2, and more ggplot2 enhancements

Home Page:http://daattali.com/shiny/ggExtra-ggMarginal-demo/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

preventing fill for density plot in densigram marginal

IndrajeetPatil opened this issue · comments

Thank you so much for introducing the densigram! Really stoked about using it.

I was trying it out, but I feel like it is still missing something:
In particular, it looks good only with the (black-and-white) defaults and loses its allure once fill arguments are provided.

For example,

# loading needed libraries
library(ggExtra)
library(ggplot2)
library(cowplot)

# preparing basic plot
set.seed(30)
df <- data.frame(x = rnorm(500, 50, 10), y = runif(500, 0, 50))
p2 <- ggplot(df, aes(x, y)) + geom_point()

# trying out densigram
cowplot::plot_grid(
# with default color fill
ggMarginal(p2, xparams = list(colour = "black"),
           yparams = list(colour = "black"), type = "densigram"),

# without default color fill
ggMarginal(p2, xparams = list(colour = "black", fill = "red"),
            yparams = list(colour = "black", fill = "blue"), type = "densigram"),
nrow = 1,
ncol = 2
)

To go back to the python example I had shown in my original issue (#118), this is the behavior I was expecting with densigram:

image

Here, the fill arguments are being supplied only to the histogram component, but not the density plot component. Is this something that will be possible to do in ggMarginal?

Thanks again!

I guess we could override the fill param to be NULL for the density plot when the user choses type = "densigram". That would result in the plot looking like the one you showed. I don't feel particularly strongly about it either way. If @daattali also doesn't have strong feelings about it then I'll add this behavior in.

More generally, I was thinking people would use the alpha param when using fill with densigrams:

library(ggExtra)

ggMarginal(
  data = mtcars, x = "mpg", y = "wt", type = "densigram", 
  colour = "blue", fill = "blue", alpha = .3
)

When I was checking it out I did indeed use alpha, but I suppose that does add an additional requirement on the user. It might be simpler to just remove the fill