[R-sig-Geo] problem plotting elevational map of New Zealand

John Baumgartner johnbaums at gmail.com
Tue Aug 25 12:32:25 CEST 2015


Take a look at str(x, 1). I'm not sure why, but two raster layers are
downloaded. Try plot(x[[1]]).

On Tue, Aug 25, 2015 at 8:23 PM, Christopher Lusk <clusk at waikato.ac.nz>
wrote:

> Hi - I've been making elevational maps of several countries, but for some
> reason the code won't work for New Zealand:
>
> library(raster)
> x <- getData('alt', country = "NZ")
> plot(x)
> colfunc <- colorRampPalette(c("black", "white"))
> plot(x,col=(colfunc(50)), cex.axis=1, las=1)
> title(xlab = "Longitude (degrees E)", ylab="Latitude (degrees S)")
>
> This makes perfectly good maps of plenty of countries (e.g. Australia,
> Spain, France) but when I write "country = "NZ"  " on line 2, here's what
> happens:
>
> > x <- getData('alt', country = "NZ")
> trying URL 'http://biogeo.ucdavis.edu/data/diva/msk_alt/NZL_msk_alt.zip'
> Content type 'application/zip' length 649397 bytes (634 Kb)
> opened URL
> downloaded 634 Kb
>
> returning a list of RasterLayer objects
> > plot(x)
> Error in xy.coords(x, y, xlabel, ylabel, log) :
>   'x' is a list, but does not have components 'x' and 'y'
> > colfunc <- colorRampPalette(c("black", "white"))
> > plot(x,col=(colfunc(50)), cex.axis=1, las=1)
> Error in xy.coords(x, y, xlabel, ylabel, log) :
>   'x' is a list, but does not have components 'x' and 'y'
> > title(xlab = "Longitude (degrees E)", ylab="Latitude (degrees S)")
>
> I'd really appreciate advice on how to fix this, or other approaches that
> might work for NZ. As you can see above, R found the data, but didn't make
> the map.
>
> thanks
>
> Chris
>
> --
> Dr. Chris Lusk
> Environmental Research Institute
> The University of Waikato
> Private Bag 3105, Hamilton
> New Zealand / Aotearoa
> http://sci.waikato.ac.nz/sites/clusk/
> Ph 64 7 838 4205
> ~  ~  ~  ~  ~  ~  ~
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list