[R-sig-Geo] subplots of maps in R using hydroTSM package

Edzer Pebesma edzer.pebesma at uni-muenster.de
Mon Nov 24 09:40:51 CET 2014


It looks like hydroTSM uses sp::spplot to plot maps; this function uses
lattice which builds on grid graphics, and hence mfrow does not work.

As hydrokrige does not return the trellis plot object but merely plots
it, it's not easy to arrange plots using lattice::print.trellis

It seems relatively easy though to figure out what hydrokrige does, and
then do that yourself, using spplot and print.trellis; see

library(gstat)
demo(krige)

for examples.

On 11/23/2014 06:13 PM, Zilefac Elvis wrote:
> Hello,
> Please I need help with maps in R using the hydroTSM package.
> I am doing some map work using this wonderful package but encountered a problem using "par".
> My intention is to generate 4 plots and show them on same window as follows:
> 
> 
> if (dev.cur() == 1) x11(width=14,height=8)
> par(mfrow=c(4,4),mai = c(0.8, 0.6, 0.1, 0),oma=c(0,1.4,6,0.1))
>  
> library(hydroTSM)
> 
> ############
> ## Loading the monthly time series of precipitation within the Ebro River basin.
> data(EbroPPtsMonthly)
> 
> ## Loading the gis data
> data(EbroPPgis)
> 
> ## Loading the shapefile with the subcatchments
> data(EbroCatchmentsCHE)
> 
> ## Projection for the Subcatchments file
> # European Datum 50, Zone 30N
> require(sp)
> p4s <- CRS("+proj=utm +zone=30 +ellps=intl +units=m +no_defs")
> 
> ## Selecting the first day of 'EbroPPtsMonthly' for all the stations.
> # The first column of 'EbroPPtsMonthly' has the dates
> x.ts <- as.numeric(EbroPPtsMonthly[1, 2:ncol(EbroPPtsMonthly)])
> 
> ## Setting the name of the gauging stations
> names(x.ts) <- colnames(EbroPPtsMonthly[1,2:ncol(EbroPPtsMonthly)])
> 
> ##################################################
> ## 1) IDW interpolation and plot
> ## Probably you will need to resize your window 
> ## Not run: 
> x.idw <- hydrokrige(x.ts= x.ts, x.gis=EbroPPgis, 
>                     X="EAST_ED50", Y="NORTH_ED50", sname="ID", bname="CHE_BASIN_NAME",
>                     type= "cells",
>                     subcatchments= EbroCatchmentsCHE,
>                     cell.size= 3000, 
>                     ColorRamp= "Precipitation",
>                     main= "IDW Precipitation on the Ebro")
> 
> ## End(Not run)
>  
> 
> 
> However, the existing plot disappears everytime I run this code.
> 
> Question1: How can I run this code 4 times and show the 4 maps on 1 plot window as defined by 
> par(mfrow=c(4,4))?
> 
> Question2: Is it possible to convert the X and Y axes values from UTM to lat and lon and show them on the map?
> 
> Many thanks for your insighful replies.
> 
> Zilefac.
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Edzer Pebesma,  Co-Editor-in-Chief Computers & Geosciences
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAC227795

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20141124/5400e8f0/attachment.bin>


More information about the R-sig-Geo mailing list