r - How to plot multiple variogram plots with different title using loop/lapply function? -
i have csv file contains hourly pm10 concentration of 1 march 7 march. please, download here. have plotted variogram (total 161) in loop automap package.
library(sp) library(gstat) library(rgdal) library(automap) library(latticeextra) seoul1to7<-read.csv("seoul1to7.csv") seoul1to7[seoul1to7==0] <-na seoul1to7 <- na.omit(seoul1to7) seoul1to7_split<-split(seoul1to7,seoul1to7$time) seq(seoul1to7_split) vars<-lapply(seq(seoul1to7_split), function(i) { dat<-seoul1to7_split[[i]] coordinates(dat)<-~lon+lat proj4string(dat) <- "+proj=longlat +datum=wgs84" dat <- sptransform(dat, crs("+proj=utm +north +zone=52 +datum=wgs84")) variogram<-autofitvariogram(log(pm10)~1,dat, model="sph") plot<- plot(variogram,plotit=false, asp=1) return(plot) }) vars[[1]] vars[[2]]
here, can individual plot vars[[1]],vars[[2]]...
etc variogram has same title. now, want plot variogram image different title in loop. want variograms title like, "variogram 2012-03-01 1.00", "variogram 2012-03-01 2.00" .....etc.
a<-as.posixct(names(seoul1to7_split), format="%y%m%d%h") hours<-substr(a,1,16) hours
i keep desired different title in hours
variable "2012-03-01 01:00", "2012-03-01 02:00", "2012-03-01 03:00" ...etc.
how can plot variograms (total 161) different title using loop?
the trick use png
, dev.off
:
library(automap) data(meuse) coordinates(meuse) = ~x+y fit_for_model_type = function(model_type) { return(autofitvariogram(log(zinc) ~ dist, meuse, model = model_type)) } model_options = c("sph", "exp", "gau", "ste") list_of_variogram_models = lapply(model_options, fit_for_model_type) names(list_of_variogram_models) = model_options lapply(names(list_of_variogram_models), function(x) { png(filename = sprintf('%s.png', x)) print(plot(list_of_variogram_models[[x]])) dev.off() })
Comments
Post a Comment