make one panel blank in ggplot2

前端 未结 2 945
谎友^
谎友^ 2021-01-05 09:46
p <- ggplot(mtcars, aes(mpg, wt)) 
p + geom_point()+facet_grid(cyl ~ vs)+theme_bw()

\"Pic\"

2条回答
  •  佛祖请我去吃肉
    2021-01-05 10:30

    You change the table grobs.

    ## 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

提交回复
热议问题