Is it possible to have two different types of marginal distribution in
I tried having both types in a list (
ggMarginal(p, type = list("density", "histogram"))
), but that type
must be of length 1.
Thanks in advance for your help!
CodePudding user response:
I think you need to create both plots and swap their upper margin grobs:
library(ggExtra)
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg)) geom_point()
ph <- ggMarginal(p, type = "histogram")
pd <- ggMarginal(p, type = "density")
ph$grobs[ph$layout$name == "topMargPlot"] <-
pd$grobs[ph$layout$name == "topMargPlot"]
ph
Created on 2022-03-09 by the reprex package (v2.0.1)