Inverse of ggplotGrob?

前端 未结 3 1179
遇见更好的自我
遇见更好的自我 2020-12-02 14:35

I have a function which manipulates a ggplot object, by converting it to a grob and then modifying the layers. I would like the function to return a ggplot object not a grob

3条回答
  •  醉话见心
    2020-12-02 14:41

    You can try the following:

    p = ggplotify::as.ggplot(g)
    

    For more info, see https://cran.r-project.org/web/packages/ggplotify/vignettes/ggplotify.html

    It involves a little bit of a cheat annotation_custom(as.grob(plot),...), so it may not work for all circumstances: https://github.com/GuangchuangYu/ggplotify/blob/master/R/as-ggplot.R

提交回复
热议问题