lundi 13 avril 2015

Reset graph at the end of the loop :could not find function "device" error


Vote count:

0




I am trying to generate plots by looping ,here is my code:


n <- unique(wide_data$Product.Code)[1:3]


for (i in n)


{


my.prod2 <- filter(tall_bind, Product.Code == i, Date > ymd("2012/04/01"))


dev.new()


mypath <- file.path("C:","R","SAVEHERE",paste("myplot_", i, ".jpg", sep = ""))


jpeg(file=mypath)


mytitle = paste("Plot for product", i)


p <- qplot(Date, Sold, data = my.prod2, geom = "line", main=mytitle, group = Model, colour = Model) + facet_grid(Model ~ .)


ggsave("myplot_", i, plot=p, device= "jpg" )


}


I get the following error for the above code:


Saving 6.67 x 6.67 in image


Error in ggsave("myplot_", i, plot = p, device = "jpg") :


could not find function "device"


Earlier when I used dev.off() at the end of the loop, I found that though the graphs were being generated they were totally blank.


Could someone please help me understand where is the mistake in my code.


Thank you



asked 1 min ago







Reset graph at the end of the loop :could not find function "device" error

Aucun commentaire:

Enregistrer un commentaire