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


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

--

Legend:

Unmodified
Added
Removed
Modified
  • udg/ecoms/RPackage/examples

    v12 v13  
    6060+               color.palette = topo.colors)
    6161}}}
     62
     63[[Image(TmeanJan.png)]]
     64
     65Next, 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`.
     66
     67{{{
     68> # Selection of point locations. Requires "sp::spDistsN1" to compute geographic distances
     69> library(sp)
     70> index <- rep(NA, nrow(locations))
     71> for (i in 1:length(index)) {
     72+      index[i] <- which.min(spDistsN1(openDAP.query$LatLonCoords[ ,2:1], locations[i, ]))     
     73+ }
     74> locations.data <- openDAP.query$MemberData[[1]][ ,index]
     75> colnames(locations.data) <- city.names
     76> str(locations.data)
     77 num [1:310, 1:4] 7.71 8.78 10.77 10.88 11.55 ...
     78 - attr(*, "dimnames")=List of 2
     79  ..$ : NULL
     80  ..$ : chr [1:4] "Sevilla" "Madrid" "Santander" "Zaragoza"
     81}}}
     82
     83The object `locations.data` is a matrix in which time series are arranged in columns for each of the four locations selected.
     84
     85{{{
     86> ylimits <- c(floor(min(locations.data)), ceiling(max(locations.data)))
     87> plot(locations.data[ ,1], ty='n', ylim = ylimits, axes=FALSE, ylab="degC", xlab="Year")
     88> axis(1,at = seq(1,31*11,31), labels=c(1990:1999,""))
     89> axis(2, ylim=ylimits)
     90> abline(v=seq(1,31*10,31), lty=2)
     91> for (i in 1:ncol(locations.data)) {
     92+      lines(locations.data[ ,i], col=i)
     93+ }
     94> legend("bottomleft", city.names, lty=1, col=1:4)
     95> title(main = "Mean surface Temperature January")
     96}}}
     97
     98
     99[[Image(timeSeries.png)]]