arrange multiple graphs using a for loop in ggplot2

前端 未结 4 854
有刺的猬
有刺的猬 2021-02-04 19:37

I want to produce a pdf which shows multiple graphs, one for each NetworkTrackingPixelId. I have a data frame similar to this:

> head(data)
  Net         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 20:01

    I think you would be better off writing a function for plotting, then using lapply for every Network Tracking Pixel.

    For example, your function might look like:

        plot.function <- function(ntpid){
        sub = subset(dataset, dataset$networktrackingpixelid == ntpid)
        ggobj = ggplot(data=sub, aes(...)) + geom...
        ggsave(filename=sprintf("%s.pdf", ntpid))
        }
    

    It would be helpful for you to put a reproducible example, but I hope this works! Not sure about the vector issue though..

    Cheers!

提交回复
热议问题