Inverse of ggplotGrob?

前端 未结 3 1178
遇见更好的自我
遇见更好的自我 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:38

    I would say no. ggplotGrob is a one-way street. grob objects are drawing primitives defined by grid. You can create arbitrary grobs from scratch. There's no general way to turn a random collection of grobs back into a function that would generate them (it's not invertible because it's not 1:1). Once you go grob, you never go back.

    You could wrap a ggplot object in a custom class and overload the plot/print commands to do some custom grob manipulation, but that's probably even more hack-ish.

提交回复
热议问题