## R: Classification breaks in R

19 October, 2010 (08:57) | R, Spatial analysis | By: Manuel Gimond

```# Working with classification schemes in R
#
# There are some attractive legend options that R provides such as
# a scaled classification legend for vector data
#
library(rgdal)
MEpop = readOGR(".", "Maine_pop") # Creates a SpatialPolygonsDataFrame class (sp)
#
# Reproject from latlong to UTM (using rdgal library)
MEpop.utm = spTransform(MEpop,CRS("+init=epsg:2037"))
#
# Class intervals
library(classInt)
library(RColorBrewer) # Creates nice looking color palettes
pal = brewer.pal(7,"Greens")
brks.qt = classIntervals(MEpop.utm\$POP2000, n = 7, style = "quantile")
brks.jk = classIntervals(MEpop.utm\$POP2000, n = 7, style = "jenks")
brks.eq = classIntervals(MEpop.utm\$POP2000, n = 7, style = "equal")
#
# Plot and compare breaks
par(mfrow=c(3,1))
plot(brks.eq,pal=pal,main="Equal Breaks")
plot(brks.qt,pal=pal,main="Quantile Breaks")
plot(brks.jk,pal=pal,main="Jenks Breaks")
#
#Plot and compare maps
print(spplot(MEpop.utm, "POP2000",at=brks.eq\$brks,col.regions=pal,
main = list(label="Equal breaks")),position=c(0,0.666,1,1),more=T)
print(spplot(MEpop.utm, "POP2000",at=brks.qt\$brks,col.regions=pal,
main = list(label="Quantile breaks")),position=c(0,0.333,1,.666),more=T)
print(spplot(MEpop.utm, "POP2000",at=brks.jk\$brks,col.regions=pal,
main = list(label="Jenks breaks")),position=c(0,0,1,0.333))
```

The resulting plots are shown side-by-side

To display all the color palettes available from Brewer type:

```display.brewer.all()
```