Trying to display 2 plots with ggMarginal but the plots are not recognized as such.
I'm pasting a simplified version of the code below where:
- Before adding the ggMarginal element Patchwork displays ggplots side by side as expected
- After adding marginal distributions with ggMarginal, Patchwork doesn't seem to recognize the the plot any more. The error message that I get is the following:
p1m + p2m
#> Error in p1m + p2m: non-numeric argument to binary operator
Here's the code I'm running:
library(ggplot2)
library(ggExtra)
library(patchwork)
p1 <- ggplot(mtcars) +
geom_point(aes(mpg, disp)) +
ggtitle('Plot 1')
p1m <- ggMarginal(p1,
type = "density",
size = 3)
p2 <- ggplot(mtcars) +
geom_point(aes(hp, wt, colour = mpg)) +
ggtitle('Plot 3')
p2m <- ggMarginal(p2,
type = "density",
size = 3)
p1+p2
p1m + p2m
#> Error in p1m + p2m: non-numeric argument to binary operator
Thanks a lot for your help!
Created on 2021-10-09 by the reprex package (v2.0.1)

