Annotate outside plot area once in ggplot with facets

后端 未结 4 1132
粉色の甜心
粉色の甜心 2021-01-18 17:25

I want to add an annotation outside the plotting area in a faceted ggplot. I can get the annotation that I want, but it\'s repeated for each facet. How can I get this annota

4条回答
  •  天涯浪人
    2021-01-18 17:40

    It's in fact very easy, just have a vector of labels, where the ones you don't want to plot are the empty string "".

    library("ggplot2")
    
    ggplot(mtcars, aes(x = hp, y = mpg)) +
      geom_point() +
      annotate("text", x = -20, y = 36, label = c("XX", "", "")) +
      facet_grid(.~cyl ) + 
      coord_cartesian(xlim = c(50, 350), ylim = c(10, 35), clip = "off")
    

提交回复
热议问题