{"id":48,"date":"2010-10-19T08:57:06","date_gmt":"2010-10-19T12:57:06","guid":{"rendered":"http:\/\/web.colby.edu\/mgimond\/?p=48"},"modified":"2011-10-26T12:06:33","modified_gmt":"2011-10-26T16:06:33","slug":"r-classification-breaks-in-r","status":"publish","type":"post","link":"https:\/\/web.colby.edu\/mgimond\/2010\/10\/19\/r-classification-breaks-in-r\/","title":{"rendered":"R: Classification breaks in R"},"content":{"rendered":"<p><strong><span style=\"color: #888888\">Data for this exercise can be downloaded from<\/span><\/strong> <a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/Maine_pop.zip\">Maine_pop<\/a>.<\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\n# Working with classification schemes in R\r\n#\r\n# There are some attractive legend options that R provides such as\r\n# a scaled classification legend for vector data\r\n#\r\n# Load sample data\r\nlibrary(rgdal)\r\nMEpop = readOGR(&quot;.&quot;, &quot;Maine_pop&quot;) # Creates a SpatialPolygonsDataFrame class (sp)\r\n#\r\n# Reproject from latlong to UTM (using rdgal library)\r\nMEpop.utm = spTransform(MEpop,CRS(&quot;+init=epsg:2037&quot;))\r\n#\r\n# Class intervals\r\nlibrary(classInt)\r\nlibrary(RColorBrewer) # Creates nice looking color palettes\r\npal = brewer.pal(7,&quot;Greens&quot;)\r\nbrks.qt = classIntervals(MEpop.utm$POP2000, n = 7, style = &quot;quantile&quot;)\r\nbrks.jk = classIntervals(MEpop.utm$POP2000, n = 7, style = &quot;jenks&quot;)\r\nbrks.eq = classIntervals(MEpop.utm$POP2000, n = 7, style = &quot;equal&quot;)\r\n#\r\n# Plot and compare breaks\r\npar(mfrow=c(3,1))\r\nplot(brks.eq,pal=pal,main=&quot;Equal Breaks&quot;)\r\nplot(brks.qt,pal=pal,main=&quot;Quantile Breaks&quot;)\r\nplot(brks.jk,pal=pal,main=&quot;Jenks Breaks&quot;)\r\n#\r\n#Plot and compare maps\r\nprint(spplot(MEpop.utm, &quot;POP2000&quot;,at=brks.eq$brks,col.regions=pal,\r\nmain = list(label=&quot;Equal breaks&quot;)),position=c(0,0.666,1,1),more=T)\r\nprint(spplot(MEpop.utm, &quot;POP2000&quot;,at=brks.qt$brks,col.regions=pal,\r\nmain = list(label=&quot;Quantile breaks&quot;)),position=c(0,0.333,1,.666),more=T)\r\nprint(spplot(MEpop.utm, &quot;POP2000&quot;,at=brks.jk$brks,col.regions=pal,\r\nmain = list(label=&quot;Jenks breaks&quot;)),position=c(0,0,1,0.333))\r\n<\/pre>\n<p>The resulting plots are shown side-by-side<\/p>\n<p><span style=\"font-weight: bold\"><span style=\"color: #808080\"><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/plot13.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-49\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/plot13-430x1024.jpg\" alt=\"\" width=\"301\" height=\"717\" srcset=\"https:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/plot13-430x1024.jpg 430w, https:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/plot13-126x300.jpg 126w, https:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/plot13.jpeg 472w\" sizes=\"(max-width: 301px) 100vw, 301px\" \/><\/a><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/plot21.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-50 alignnone\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/plot21-430x1024.jpg\" alt=\"\" width=\"301\" height=\"717\" srcset=\"https:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/plot21-430x1024.jpg 430w, https:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/plot21-126x300.jpg 126w, https:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/plot21.jpeg 472w\" sizes=\"(max-width: 301px) 100vw, 301px\" \/><\/a><\/span><\/span><\/p>\n<p>To display all the color palettes available from Brewer type:<\/p>\n<pre class=\"brush: r; light: true; title: ; notranslate\" title=\"\">\r\ndisplay.brewer.all()\r\n<\/pre>\n<p><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/Brewer1.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-56\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/Brewer1-300x281.jpg\" alt=\"\" width=\"300\" height=\"281\" srcset=\"https:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/Brewer1-300x281.jpg 300w, https:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/Brewer1-1024x959.jpg 1024w, https:\/\/web.colby.edu\/mgimond\/files\/2010\/10\/Brewer1.jpeg 1059w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Data for this exercise can be downloaded from Maine_pop. The resulting plots are shown side-by-side To display all the color palettes available from Brewer type:<\/p>\n","protected":false},"author":1199,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[12807,12808],"tags":[],"_links":{"self":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts\/48"}],"collection":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/users\/1199"}],"replies":[{"embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/comments?post=48"}],"version-history":[{"count":27,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":59,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts\/48\/revisions\/59"}],"wp:attachment":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/media?parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/categories?post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/tags?post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}