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

Jon Skoien jon.skoien at jrc.ec.europa.eu
Mon Nov 24 09:48:34 CET 2014


Hi Zilefac,

Your problem is not really related to hydroTSM, but to the fact that 
hydrokrige uses spplot for plotting, which is again based on the lattice 
package. This does not use the par()-arguments.
Instead there are two other ways for producing multiple plots in one figure:
- Save each of the prediction-results from hydrokrige in a different 
column of a results-object and plot them with spplot later:
res = hydrokrige("1st dataset")
res$var2.pred = hydrokrige("2nd dataset")$var1.pred
res$var3.pred = hydrokrige("2nd dataset")$var3.pred
...
spplot(res, c("var1.pred", "var2.pred", ...))

- Use the location arguments of plot.trellis when you plot the resulting 
objects.
res1 = hydrokrige("1st dataset")
res2 = hydrokrige("2nd dataset")
print(res1, position = c(0,0,.5,.5),more=TRUE)
print(res1, position = c(0,0.5,.5,.5),more=TRUE)
....

You can in both cases turn of the plotting in hydrokrige, as the 
function will not be able to do multiplots by itself.

For your second question, you should be able to transform your 
coordinates with spTransform, if you have the proj4string of your 
coordinates.

Cheers,
Jon


On 11/23/2014 6: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
>

-- 
Jon Olav Skøien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Climate Risk Management Unit

Disclaimer: Views expressed in this email are those of the individual 
and do not necessarily represent official views of the European Commission.



More information about the R-sig-Geo mailing list