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

Christopher Lusk clusk at waikato.ac.nz
Tue Aug 25 12:23:21 CEST 2015


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]]



More information about the R-sig-Geo mailing list