tags:

views:

80

answers:

2

I have a data frame in R with POSIXct variable sessionstarttime. Each row is identified by integer ID variable of a specified location . Number of rows is different for each location. I plot overall graph simply by:

myplot <- ggplot(bigMAC, aes(x = sessionstarttime)) + geom_freqpoly()

Is it possible to create a loop that will create and save such plot for each location separately?
Preferably with a file name the same as value of ID variable?
And preferably with the same time scale for each plot?

A: 

I am not sure if I get what you want to do. From what I guess, i suggest to write a simple function that saves the plot. and then use lapply(yourdata,yourfunction,...) . Since lapply can be used for lists, it´s not necessary that the number of rows is equal.

HTH

use something like this in your function:

    ggsave(filename,scale=1.5)
ran2
Thanks ran2. Yes, lapply could be one way to go. Will have a look at it.
radek
A: 

Not entirely sure what you're asking but you can do one of two things.

a) You can save each individual plot in a loop with a unique name based on ID like so:

ggsave(myplot,filename=paste("myplot",ID,".png",sep="")) # ID will be the unique identifier. and change the extension from .png to whatever you like (eps, pdf etc).

b) Just assign each plot to an element of a list. Then write that list to disk using save That would make it very easy to load and access any individual plot at a later time.

Maiasaura
Thanks Maiasaura. Was heading more or less in the same direction with my attempts.
radek