Difference between revisions of "Plotting maps"
Jump to navigation
Jump to search
Line 4: | Line 4: | ||
I decided to give up on plotting nice maps with [http://grass.itc.it grass]. The ps.map function is very powerful, but hard to remember for my not-so-frequent use. R has great plotting capabilities, and of course it does maps. It has an easy [http://cran.r-project.org/src/contrib/Descriptions/spgrass6.html grass interface]. What else do you want (importing other GIS formats? Try [http://cran.r-project.org/src/contrib/Descriptions/rgdal.html rgdal]). Plotting GIS data is very nicely implemented in the [http://cran.r-project.org/src/contrib/Descriptions/sp.html sp] package, part of the [http://r-spatial.sourceforge.net/ spatial data in R] project, but getting your plot the way you want is quite challenging. | I decided to give up on plotting nice maps with [http://grass.itc.it grass]. The ps.map function is very powerful, but hard to remember for my not-so-frequent use. R has great plotting capabilities, and of course it does maps. It has an easy [http://cran.r-project.org/src/contrib/Descriptions/spgrass6.html grass interface]. What else do you want (importing other GIS formats? Try [http://cran.r-project.org/src/contrib/Descriptions/rgdal.html rgdal]). Plotting GIS data is very nicely implemented in the [http://cran.r-project.org/src/contrib/Descriptions/sp.html sp] package, part of the [http://r-spatial.sourceforge.net/ spatial data in R] project, but getting your plot the way you want is quite challenging. | ||
+ | |||
+ | ==Required packages== | ||
+ | |||
+ | spgrass6 reads data from the GRASS database. Sp implements spplot and lattice is used to define the colours (trells.par.set). | ||
+ | |||
+ | library(sp) | ||
+ | library(spgrass6) | ||
+ | library(lattice) | ||
==Procedure== | ==Procedure== | ||
Line 9: | Line 17: | ||
Here's what I came up with: | Here's what I came up with: | ||
− | |||
− | |||
paute <- rast.get6("paute_z") | paute <- rast.get6("paute_z") | ||
colours <- topo.colors(1000) # if you want pretty topographic colours | colours <- topo.colors(1000) # if you want pretty topographic colours |
Revision as of 04:32, 5 May 2008
Introduction
I decided to give up on plotting nice maps with grass. The ps.map function is very powerful, but hard to remember for my not-so-frequent use. R has great plotting capabilities, and of course it does maps. It has an easy grass interface. What else do you want (importing other GIS formats? Try rgdal). Plotting GIS data is very nicely implemented in the sp package, part of the spatial data in R project, but getting your plot the way you want is quite challenging.
Required packages
spgrass6 reads data from the GRASS database. Sp implements spplot and lattice is used to define the colours (trells.par.set).
library(sp) library(spgrass6) library(lattice)
Procedure
Here's what I came up with:
paute <- rast.get6("paute_z") colours <- topo.colors(1000) # if you want pretty topographic colours colours <- gray(c(rep(100,10),100:15)/100) # for greyscale colours trellis.par.set(sp.theme(regions=list(col = colours))) scale = list("SpatialPolygonsRescale", layout.scale.bar(height=0.1), offset = c(690000,9735000), scale = 20000, fill=c("transparent","black")) text1 = list("sp.text", c(690000,9740000), "0") text2 = list("sp.text", c(710000,9740000), "20 km") arrow = list("SpatialPolygonsRescale", layout.north.arrow(type=1), offset = c(698000,9720000), scale = 10000) spplot(paute,draw = T, colorkey=list(space="right", height=0.5), cuts=127, scales=list(draw=T), sp.layout=list(scale,text1,text2,arrow))
Good to know:
- cuts defines the number of colour intervals. The default is 15 and that's not really nice for continuous DEM images
- the colorkey options are part of levelplot {lattice} and are quite customizable