wiki:udg/ecoms/RPackage/examples

Version 42 (modified by juaco, 8 years ago) (diff)

--

# EXAMPLE: Loading and plotting various members:

# Total precipitation of January 2010 forecasted in October 2009 (lead month 3) by the System4 model (seasonal range, 15 members) # is next represented for each member, using the spplot method for the SPatialGridDataFrame class of library sp:

gg.pr <- loadSeasonalForecast("System4_seasonal_15", var="tp", members=NULL, lonLim=c(-30,20), latLim=c(-12,15), season=1, years=2010, leadMonth=3)

names(gg.pr) str(gg.pr$MemberData?)

pr.list <- lapply(1:length(gg.pr$MemberData?), function(x) colSums(gg.pr$MemberData?x?)) df <- do.call("data.frame", pr.list) names(df) <- names(gg.pr$MemberData?)

class(gg.pr$LonLatCoords?) sgdf <- SpatialGridDataFrame?(gg.pr$LonLatCoords?, df)

spplot(sgdf, scales=list(draw = TRUE), col.regions = rev(terrain.colors(50)), at = seq(0, ceiling(max(sgdf@data)),10))

data(world_map) wl <- as(world_map, "SpatialLines?") l1 <- list("sp.lines", wl)

spplot(sgdf, zcol = 1:4, scales=list(draw = TRUE), col.regions = rev(terrain.colors(50)), at = seq(0, ceiling(max(sgdf@data)),10), sp.layout = list(l1))