How to plot multiple semi-variogram from a single dataset efficiently in R?
Orpheus,
here's one option to get what you want.
The problem with fitting that many variograms is that if you want to
specify each variogram individually (i.e. nugget, range, model etc.),
there is no way to automate this with loops or thelike.
You can, however, use library(automap) to automatically fit a variogram
to your data. Then a possible solution could look like this:
### in order to use latticeCombineGrid() you need to use ##################
### library(devtools) to install library(Rsenal) ##########################
# install.packages(devtools)
# library(devtools)
# install_github("environmentalinformatics-marburg/Rsenal")
###########################################################################
library(sp)
library(gstat)
library(rgdal)
library(automap)
library(Rsenal)
seoul311 <- read.csv("Downloads/seoul1to7.csv")
seoul311 <- na.omit(seoul311)
### first we split seoul311 by time into a list rather than subsetting
manually
seoul311_splt <- split(seoul311, seoul311$time)
### now we loop (using lapply()) over each seoul311_splt entry and
calculate
### variogram using autofitVariogram and return the variogram plot
vars <- lapply(seq(seoul311_splt), function(i) {
dat <- seoul311_splt[[i]]
coordinates(dat) <- ~LON+LAT
proj4string(dat) <- "+proj=longlat +datum=WGS84"
dat <- spTransform(dat, CRS("+proj=utm +north +zone=52 +datum=WGS84"))
variogram <- autofitVariogram(PM10 ~ 1, dat)
plt <- plot(variogram, plotit = FALSE, asp = 1)
### in case you do not want to fix xlim and ylim to be identical
### for each plot just comment out the following line or change
### values as you see fit
plt <- update(plt, xlim = c(-1000, 45000), ylim = c(0, 1000))
return(plt)
})
### now we actually have 23 * 7 variogram plots which we will combine
### into 23 hourly plots using latticeCombineGrid()
hrs <- substr(names(seoul311_splt), 9, 10)
plts_hrs <- lapply(seq(unique(hrs)), function(j) {
indx <- hrs %in% unique(hrs)[j]
hr_plt <- vars[indx]
return(latticeCombineGrid(hr_plt, layout = c(3, 3)))
})
### plot for hour 1
plts_hrs[[1]]
### plot for hour 23
plts_hrs[[23]]
### ...
HTH
Best,
Tim
On 17.08.2015 09:43, Uzzal wrote:
Actually I asked this same question to some other forum but unfortunate I didn't get the appropriate response. But I am kind of struck with this problem. I am giving the link of my problem previously posted in other forum: (really sorry for that) http://stackoverflow.com/questions/31762461/how-to-plot-multiple-semi-variogram-from-a-single-dataset-efficiently-in-r?noredirect=1#comment51767989_31762461 I want variogram time wise. For example, thevariogram for 1.00 am of 1 march to 7 march in one plot. That means 7 variograms in one plot. in such a way there will be 23 plot contains (23*7) variogram. Thanks in adv! ance. Orpheus Uzzal Kumar Dash Master's student Air Quality & Climate Modeling Laboratory (AqCliMB) School of Environmental Science and Engineering (SESE) Gwangju Institute of Science and Technology (GIST) 123 Cheomdan-gwagiro, Buk-gu, Gwangju 500-712 Republic of Korea web: http://aqclimb.gist.ac.kr/
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
##################################### Tim Appelhans Department of Geography Environmental Informatics Philipps Universit?t Marburg Deutschhausstra?e 12 35032 Marburg (Paketpost: 35037 Marburg) Germany Tel +49 (0) 6421 28-25957 http://environmentalinformatics-marburg.de/ [[alternative HTML version deleted]]