Make one panel empty in ggplot2

p <- ggplot(mtcars, aes(mpg, wt)) 
p + geom_point()+facet_grid(cyl ~ vs)+theme_bw()

Pic

I would like to make the panel (1 versus 8 in the lower right corner) empty where there are no data points, but at the same time I would like to keep this diagram.

therefore facet_wrap(cyl ~ vs)could not solve my problem.

Perhaps a more general question is that can I position each panel in ggplot2?

+4
source share
2 answers

You change the lumps of table.

## get the table grobs
g1 <- ggplot_gtable(ggplot_build(p))

library(gtable)
library(grid)
## here the main modification
## change one panel by a new rectangle.
pp <- gtable_add_grob(g1,rectGrob(gp=gpar(col=NA)),t=8,l=6,b=8,r=6)
grid.draw(pp)

enter image description here

+9
source

You can do this, but not with facet_wrap(as far as I know). Create your own individual subheadings. For a detailed step-by-step approach, see My answer here .

Create an empty area and with the package gridExtrayou can combine the graphs:

library(gridExtra)
library(grid)

blank <- grid.rect(gp=gpar(col="white"))

grid.arrange(plot1, plot2, blank, plot3, ncol=2)

(IMHO).

+7

All Articles