Multiple ggplots with magrittr tee operator

前端 未结 3 866
迷失自我
迷失自我 2021-02-14 23:04

I am trying to figure out why the tee operator, %T>%, does not work when I pass the data to a ggplot command.

This works fine

library(ggplot2)
library(dp         


        
3条回答
  •  半阙折子戏
    2021-02-14 23:56

    Note that a returned ggplot object is a list with $data field. This can be taken advantaged of. Personally I think the style is cleaner:)

    ggpass=function(pp){
    print(pp)
    return(pp$data)
    }
    mtcars %>%
      {ggplot() + geom_point(aes(cyl, mpg))} %>% ggpass() %>%
      {ggplot() + geom_point(aes(mpg, cyl))}
    

提交回复
热议问题