Using facet tags and strip labels together in ggplot2

后端 未结 4 510
再見小時候
再見小時候 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 23:07

    This can be done using only geom_text() :

    data_text <- data.frame(
      cyl   = c(4, 6, 8, 4, 6, 8, 4, 6, 8),
      gear  = c(3, 3, 3, 4, 4, 4, 5, 5, 5)
      label = c('(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)', '(i)')
    )
    
    ggplot(mtcars, aes(mpg, wt)) +
    geom_point() +
    facet_grid(gear ~ cyl) +
    geom_text(data=data_text, aes(x=12, y=5, label=label), fontface='bold', size=4)
    

提交回复
热议问题