[R-sig-Geo] Map colouring via classInt and colour Brewer

Alessandra Carioli alessandracarioli at gmail.com
Wed Mar 5 12:10:38 CET 2014


Dear all,

I have been trying to colour my maps using the same variable at different points in time employing the classInt and the RColorBrewer palettes.
Although the matching between the map areas and data file is correct (I have checked), the colouring is wrong every time. I am sure the error is quite silly but I can’t understand where it lies…
I have tried using a custom made palette or fixed breaks, but the colouring just does not work the right way!
Any help on the matter would be greatly appreciated!

Ale

Library(classInt)
#number of class intervals
nclassint <- 7
# variable to be plotted
varofint <- varT1
#define class intervals
cat3 <- classIntervals(varofint, nclassint,style = "jenks")
categ <- cat3
colpal   = brewer.pal(nclassint,"RdBu")
# Code for map: I want the reverse of the palette, from blue to red
colors <- findColours(categ,rev(colpal))
bins <- categ$brks
lb <- length(bins)


plot(shapefile, col=rev(colpal),axes=F)
title("Total Fertility Rate 1981", cex=1)
legend(1096133,4844461,fill=rev(colpal),legend=paste(round(bins[-length(bins)],2)
                                        ,"-",round(bins[-1],2)),cex=0.6, bg="white")



More information about the R-sig-Geo mailing list