[R-sig-Geo] Graph of attribute per postal code

Tobias Rüttenauer ruettenauer at sowi.uni-kl.de
Mon Jul 11 11:13:10 CEST 2016


Dear Isa-May,

I think the easiest way is to use the choropleth command of the GISTools
package (ggplot is another option). However, you have to transform your
dataframe into a SpatialPolygonsDataFrame. That means you need to merge your
dataframe to a shapefile or some other spatial projection of Belgium (see
package sp).

You can find some examples for choropleth mapping here:
https://rpubs.com/chrisbrunsdon/958

To include four different graphs in one plot you have to set the graphical
parameters to par(mfrow=c(2,2)):

library(GISTools)
data(georgia)

shades1 <- auto.shading(georgia$MedInc, n = 6, cutter = rangeCuts, cols =
brewer.pal(6, 
 
"Greens"))
shades2 <- auto.shading(georgia$PctBlack, n = 6, cutter = rangeCuts, cols =
brewer.pal(6, 
 
"Blues"))
shades3 <- auto.shading(georgia$PctPov, n = 6, cutter = rangeCuts, cols =
brewer.pal(6, 
 
"Reds"))
shades4 <- auto.shading(georgia$PctEld, n = 6, cutter = rangeCuts, cols =
brewer.pal(6, 
 
"Greys"))

par(mfrow=c(2,2),oma=c(0,0,0,0), mar=c(0,0,0,0))   # 2 graphs per col, 2
graphs per row, no margins

choropleth(georgia, georgia$MedInc, shades1)
choro.legend(-82, 35.27, shades1, title = "MedInc", cex=0.8, bty="n")

choropleth(georgia, georgia$PctBlack, shades2)
choro.legend(-82, 35.27, shades2, title = "PctBlack", cex=0.8, bty="n")

choropleth(georgia, georgia$PctPov, shades3)
choro.legend(-82, 35.27, shades3, title = "PctPov", cex=0.8, bty="n")

choropleth(georgia, georgia$PctEld, shades4)
choro.legend(-82, 35.27, shades4, title = "PctEld", cex=0.8, bty="n")

par(mfrow=c(1,1))

A very good introduction to spatial mapping can be found in Brunsdon &
Comber (2015): "An indroduction to R for spatial analysis and mapping",
Sage.

Best
Tobias



> -----Ursprüngliche Nachricht-----
> Von: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] Im Auftrag von
Isa-
> May Kennes
> Gesendet: 09 July 2016 00:31
> An: r-sig-geo at r-project.org
> Betreff: [R-sig-Geo] Graph of attribute per postal code
> 
> Dear all,
> 
> 
> I am quite new to R and have a question related to making graphs based on
> postal codes.
> 
> I have a dateset in which each element has a postal code in Belgium,
> dataset$zip. There are some other attributes like the exposure in days,
> dataset$exposure.
> 
> I would like to make a plot of the map of Belgium, with for different
ranges of
> exposures different colors per postal code. It could for example resemble
> something like this (not the upper right graph):
> 
> [http://www.eurosurveillance.org/images/dynamic/EE/V20N01/Hens_fig2.png]
> 
> 
> How can I achieve this?
> 
> 
> Thanks in advance,
> 
> Bestregards,
> 
> Isa-May
> 
> 	[[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



More information about the R-sig-Geo mailing list