I want to show both the right and the bottom margin, but not the combination of both. Is this possible with facet_grid?
library(ggplot2)
ggplot(mtcars, aes(x = hp, group = vs)) +
geom_density() +
facet_grid(am ~ vs, switch = "y", margins = TRUE)
I tried to fix it by manually providing the factors to the margin
argument but that doesn't help. Also, the R Documentation does not help me.
Current outcome
Desired outcome
such things are trial an error for me since I don't see the bigger pictures how the entries in gt
relate to the end form:
library(ggplot2)
p<-
ggplot(mtcars, aes(x = hp, group = vs)) +
geom_density() +
facet_grid(am ~ vs, switch = "y", margins = TRUE)
gt = ggplotGrob(p)
keep <- !grepl("[3br]-3$",gt$layout$name)
gt$layout <- gt$layout[keep,]
gt$grobs <- gt$grobs[keep]
plot(gt)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With