0

I want to plot the map of climate zones of Australia. Relevant files (ASCII file) have been downloded from: http://www.bom.gov.au/web01/ncc/www/climatology/climate-classification/kpngrp.zip

The orginal map looks like this.

enter image description here

But when I used the ASCII file to re-plot this map, I cannot make it. The used code is:

library(ggplot2);library(raster)
r<-raster("kpngrp.txt")
plot(r)

How do I fix this to plot the map?

2
  • There are way more than 6 levels in that raster unique(getValues(r)) Commented May 12, 2017 at 2:22
  • Thanks for your information. Do you the method to using the raster file to make the map? Commented May 12, 2017 at 3:10

1 Answer 1

2

You first have to properly read your dataset, which is not a raster file, but a txt. The first lines of the header provide information about "format" and georeferencing:

ncols 1681
nrows 1361
xllcorner 112
yllcorner -44
cellsize 0.025
NODATA_value -9999

to properly read the data and convert it to a raster object, you can therefore do:

infile <- "/home/lb/Temp/buttami/kpngrp.txt"
data <- as.matrix(read.table(infile, skip = 6)) 
data[data == -9999] = NA
rr <- raster(data, crs = "+init=epsg:4326")
extent(rr) = c(112, 112+0.025*1681, -44, -44+0.025*1361)

> rr
class       : RasterLayer 
dimensions  : 1361, 1681, 2287841  (nrow, ncol, ncell)
resolution  : 0.025, 0.025  (x, y)
extent      : 112, 154.025, -44, -9.975  (xmin, xmax, ymin, ymax)
coord. ref. : +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       : layer 
values      : 0, 42  (min, max)

now, to plot it you can use several approaches. However, to get something nice you'll first have to remove the "ocean" data by masking with a vector shapefile:

adm <- getData("GADM", country="AUS", level=1)
rr = mask(rr, adm)
plot(rr)

enter image description here

NOte that the plot shows more "colors" than your example, since I think they aggregated the Koppen regions by larger "categories". TO obtain a map osimilar to that you will have to "join" several values of the original ASCII in a smaller number of classes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.