Changes between Version 12 and Version 13 of udg/ecoms/RPackage/examples

Ignore:
Timestamp:
Apr 19, 2013 10:50:02 AM (9 years ago)
Comment:

--

Legend:

Unmodified
 v12 +               color.palette = topo.colors) }}} [[Image(TmeanJan.png)]] Next, we plot the time series for the selected locations. To this aim, we calculate the nearest grid points to the specified locations. Note that for this task we have chosen the function spDistsN1 from R package sp. {{{ > # Selection of point locations. Requires "sp::spDistsN1" to compute geographic distances > library(sp) > index <- rep(NA, nrow(locations)) > for (i in 1:length(index)) { +      index[i] <- which.min(spDistsN1(openDAP.query$LatLonCoords[ ,2:1], locations[i, ])) + } > locations.data <- openDAP.query$MemberData[[1]][ ,index] > colnames(locations.data) <- city.names > str(locations.data) num [1:310, 1:4] 7.71 8.78 10.77 10.88 11.55 ... - attr(*, "dimnames")=List of 2 ..$: NULL ..$ : chr [1:4] "Sevilla" "Madrid" "Santander" "Zaragoza" }}} The object locations.data is a matrix in which time series are arranged in columns for each of the four locations selected. {{{ > ylimits <- c(floor(min(locations.data)), ceiling(max(locations.data))) > plot(locations.data[ ,1], ty='n', ylim = ylimits, axes=FALSE, ylab="degC", xlab="Year") > axis(1,at = seq(1,31*11,31), labels=c(1990:1999,"")) > axis(2, ylim=ylimits) > abline(v=seq(1,31*10,31), lty=2) > for (i in 1:ncol(locations.data)) { +      lines(locations.data[ ,i], col=i) + } > legend("bottomleft", city.names, lty=1, col=1:4) > title(main = "Mean surface Temperature January") }}} [[Image(timeSeries.png)]]