Ervan
Ervan

Reputation: 184

R: Remove border when plotting with ggplot2 + ggExtra + cowplot

I couldn't find the way not to plot the outer frame when combining graphs through ggplot2 + ggExtra + cowplot. I am not sure where I have to tell R, but suspect the issue to lie in ggExtra. Here is an example:

require(ggplot2)
require(cowplot)
require(ggExtra)

# Creat a graph
A <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) +     geom_point(size = 2.5)

# Add marginal histogram
B <- ggExtra::ggMarginal(A,type = 'histogram', margins = 'x', size = 9)

# Combine through cowplot
combo <- plot_grid(B,B,labels=c("A","B"))
plot(combo) # looks fine

# Re-combine through cowplot
plot_grid(B,combo,ncol=1,rel_heights = c(2,3)) # that's where I got an unwanted nasty frame around 'combo'

i.e. the 2 graphs below

Any hint would be greatly appreciated!

Upvotes: 2

Views: 1570

Answers (1)

tauft
tauft

Reputation: 575

p <- plot_grid(B,combo,ncol=1,rel_heights = c(2,3))
p <- p + panel_border(remove = TRUE)

https://rdrr.io/cran/cowplot/man/panel_border.html

Upvotes: 2

Related Questions