top of page

GIS with R

#Creating Cartogram

 

library(cartogram)

carto = cartogram(tracts, "bachelor")

 

breaks = quantile(tracts$AveHHY, na.rm=T)

categories = as.numeric(cut(tracts$AveHHY, breaks))

 

palette = colorRampPalette(c("red", "navy"))

ramp = palette(4)

colors = ramp[categories]

 

#Create PNG file for Cartogram

png(filename="Cartogram.png",width=600,height=400, pointsize=12)

 

plot(carto, col=colors)

labels = sapply(1:4, function(z) paste(round(breaks[z]), '-', round(breaks[z + 1])))

legend(x="bottomright", pch=15, col=ramp, legend= labels)

 

dev.off()

© 2017 by Benjamin Antolin. Proudly created with Wix.com

bottom of page