Marginal plots with other geoms for the main plot
crsh opened this issue · 1 comments
crsh commented
Hi Dean,
as per our brief Twitter conversation, here's the example where ggMarginal()
doesn't work when applied to something other than a scatterplot. As I said, I'm not sure this is a bug; I was under the impression that other geoms are simply not supported.
library("ggplot2")
library("ggExtra")
contour_plot <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
stat_density_2d() +
guides(color = FALSE, alpha = FALSE) +
theme()
ggMarginal(contour_plot, type = "histogram", groupColour = TRUE, groupFill = TRUE)
Error: No geom_point layer was found in your scatter plot
If I add invisible points, it works:
contour_plot2 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point(alpha = 0) +
stat_density_2d() +
guides(color = FALSE, alpha = FALSE) +
theme()
ggMarginal(contour_plot2, type = "histogram", groupColour = TRUE, groupFill = TRUE)
daattali commented
Ah yes, the code does explicitly look for a scatterlpot since that's technically what it's meant to support. If it works for other plot types, that's a nice surprise