Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just to demonstrate that a simpler example seems to work...</p> <p><img src="https://i.stack.imgur.com/cRWp6.png" alt="new jersey"></p> <pre><code>library(ggplot2) library(scales) library(maps) csv.file &lt;- "http://www.census.gov/popest/data/maps/2011/maps-county2011.csv" mydf &lt;- read.csv(csv.file, skip = 4, header = TRUE, check.names = FALSE) mydf &lt;- mydf[, c(1, 2, 5, 10, 11)] # we can drop most columns colnames(mydf) &lt;- c("code", "subregion", "population", "density", "area") mydf$population &lt;- as.numeric(gsub(",", "", mydf$population)) # remove commas mydf$area &lt;- as.numeric(gsub(",", "", mydf$area)) # remove commas nj.pop &lt;- mydf[substr(mydf$code, 1, 3) == '340', ] # new jersey code is 34000 nj.pop &lt;- nj.pop[2:nrow(nj.pop), ] # drop first row i.e. new jersey state itself nj.pop$subregion &lt;- tolower(gsub(" County", "", nj.pop$subregion)) nj.pop$subregion &lt;- gsub("\\.", "", nj.pop$subregion) nj.pop$density_d &lt;- cut(nj.pop$density, breaks = c(0,30,100,300,500,1000,3000,5000,100000), dig.lab = 6, include.lowest = TRUE) nj.pop nj.shp &lt;- map_data("county") # grab... nj.shp &lt;- nj.shp[nj.shp$region == 'new jersey', ] # ...and subset identical(unique(nj.shp2$subregion), unique(nj.pop$subregion)) # should be TRUE nj.both &lt;- merge(nj.pop, nj.shp2, by = "subregion") p &lt;- ggplot(nj.both, aes(long, lat, group = group)) + geom_polygon(aes(fill = density_d), colour = alpha("white", 1/2), size = 0.2) + scale_fill_brewer(palette = "PuRd") + coord_equal() print(p) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload