Using facet tags and strip labels together in ggplot2

后端 未结 4 539
再見小時候
再見小時候 2021-01-02 22:21

I\'d like to create a figure using ggplot2\'s facet_grid, like below:

# Load ggplot2 librar         


        
4条回答
  •  余生分开走
    2021-01-02 22:54

    Of course, I find a solution immediately after asking. The problem appears to be that tag_facet sets strip labels to element_blank, which can be fixed by calling theme after calling tag_facet.

    # Load libraries
    library(ggplot2)
    library(egg)
    #> Warning: package 'egg' was built under R version 3.5.3
    #> Loading required package: gridExtra
    
    # Create plot
    p <- ggplot(mtcars, aes(mpg, wt)) 
    p <- p + geom_point() 
    p <- p + facet_grid(gear ~ cyl)
    p <- tag_facet(p)
    p <- p + theme(strip.text = element_text())
    print(p)
    

    Created on 2019-05-09 by the reprex package (v0.2.1)

提交回复
热议问题