Note that there are some explanatory texts on larger screens.

plurals
  1. POMapping Census data w/ ggplot2 - Haphazard poly constructs (Now w/ Map!)
    primarykey
    data
    text
    <p>First, I apologize for the title, but I am not entirely sure how to describe what is happening with my map (hence the image inclusion). I am new to mapping with ggplot2, and for my first 'out of tutorial' map, I am attempting to display census data by tract in DC. Searching through the tutorials seems to support the procedure I have taken, but clearly I am veering off course (and I have not seen another instance of this).</p> <p>The goal has been to merge data from a .csv I have prepared with a shapefile containing the Census tract polys. Initially, I thought it had something to do with the ordering of rows, but explicitly accounting for this does not seem to have changed anything.</p> <p>Code:</p> <pre><code>###Combining Census data with a tract poly shapefile library(maptools) library(ggplot2) library(gpclib) setwd('~/ESRI/Trend Report Maps') #Read data tract&lt;-readShapePoly('TractPly.shp') cdata&lt;-read.csv('census00_10.csv') #Columns &gt;&gt; note that GEOID (tract) and geoid2 (cdata) are the merge keys ntract&lt;-names(tract) ncdata&lt;-names(cdata) #Prepare data for ggplot plotting of poly info (by conversion to DataFrame) gpclibPermit() tract_geom&lt;-fortify(tract,region="GEOID") #Note that this drops attribute and retains only spatial info. However, we don't really #need the attribute info since we are joining it to the other dataframe #Merge tract_poly&lt;-merge(tract_geom,cdata,by.x="id",by.y="geoid2") tract_poly&lt;-tract_poly[order(tract_poly$order),] head(tract_poly) workF&lt;-ggplot(tract_poly,aes(long,lat,group-group,fill=dmed_age)) + geom_polygon() + coord_equal() #fixes aspect ratio workF </code></pre> <p><img src="https://i.stack.imgur.com/ZvfhE.png" alt="What is going on here??"></p> <p>Yeah, visualization of Census data has seen better days. In case I am not permitted to display the map, it looks like a haphazard assortment of jagged lines (not unlike what it looks like when someone folds up paper many times and randomly cuts pieces out of it before unfolding). None of the resultant shapes look like census tracts, though the outer boundary of DC remains in tact. I can confirm that the shapefile was exported from ArcMap (where it looked as it should).</p> <p>Session info:</p> <pre><code>&gt; sessionInfo() R version 2.15.3 (2013-03-01) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] gpclib_1.5-1 ggplot2_0.9.3.1 maptools_0.8-23 lattice_0.20-13 sp_1.0-5 foreign_0.8-52 loaded via a namespace (and not attached): [1] colorspace_1.2-1 dichromat_2.0-0 digest_0.6.3 gtable_0.1.2 labeling_0.1 [6] MASS_7.3-23 munsell_0.4 plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5 [11] reshape2_1.2.2 scales_0.2.3 stringr_0.6.2 tools_2.15.3 </code></pre>
    singulars
    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.
 

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