## R sample code for plotting choropleth polygons using "maps" package ## ## y: MN lung cancer SMR 91-98,collected by Minnesota Cancer Surveillance System ## library(maps) y<-c(1.14285714285714, 1.15635738831615, 1.08396946564886, 1, 1.05555555555556, 1.10810810810811, 0.894179894179894, 0.763358778625954, 1.22137404580153, 0.81578947368421, 1.13953488372093, 0.930555555555556, 1.10483870967742, 0.889502762430939, 1.23809523809524, 0.714285714285714, 0.698630136986301, 1.02136752136752, 1.0431654676259, 0.774193548387097, 0.789115646258503, 0.760416666666667, 0.711711711711712, 0.909638554216867, 0.805405405405405, 0.717948717948718, 1.07624716553288, 0.952380952380952, 1.3125, 0.978260869565217, 1.20833333333333, 0.714285714285714, 0.982456140350877, 0.751479289940828, 1.28125, 1.22857142857143, 0.88235294117647, 1.23636363636364, 1.14285714285714, 0.660194174757282, 1.20454545454545, 0.830188679245283, 0.92, 0.660377358490566, 0.783333333333333, 0.63235294117647, 0.66, 0.936170212765957, 0.862595419847328, 0.91219512195122, 0.62962962962963, 0.8, 0.722772277227723, 1.04347826086957, 0.855491329479769, 0.807142857142857, 0.852459016393443, 1.33333333333333, 0.947368421052632, 1.10256410256410, 1, 1.11717403790925, 0.909090909090909, 0.826086956521739, 0.787234042553192, 0.897727272727273, 1, 1.03333333333333, 0.895061728395062, 1.09401709401709, 0.75, 1.08577633007600, 0.888324873096447, 0.706349206349206, 0.760869565217391, 0.868852459016393, 1.02727272727273, 0.75, 1.03333333333333, 0.779411764705882, 0.858974358974359, 1.11940298507463, 1.08333333333333, 0.75, 1.04324324324324, 0.937777777777778, 0.93939393939394) # Number of categories/shadings to be used. n.col<-4 # Setting cutoff values for different categories. # Note need to include min/max, thus number of cutoffs is (n.col+1). br <- c(min(y),0.7, 1, 1.2, max(y)) # 0: dark 1: light. See "rainbow", "hsv" and "rgb" for color shadings. shading<-gray((n.col-1):0/(n.col-1)) # Find corresponding category for each element of y. y.grp<-findInterval(y, vec=br, rightmost.closed = TRUE, all.inside = TRUE) # Find corresponding shading for each element of y. y.shad<-shading[y.grp] map("county","minnesota", fill=T, plot=T, col=y.shad, interior=T) # Adding lengend and title. leg.txt<-c("<0.7","0.7-1","1-1.2",">1.2") legend(-92.25,46.5,legend=leg.txt,fill=shading,cex=1,ncol=1,bty="n") title(main="MN Lung Cancer SMR", cex.main=2)