Introduction: In this section provides with some examples of how to deal with Spatial data in R. The main take away from this task is that R provides a wide range of functionality to manipulate, process, analyze and display spatial data. In particular R advantage over other software is that it is an ‘object-oriented’ framework, that increase the functionality and flexibility to both process and manipulate data. In the following lines of code, it is shown how by creating Spatial-type objects in R, tasks such as projection, change of extent, and plotting, becomes an easier task.
Figure A shows the class example of a two-pane plot of shopping centers in Mecklenburg County. Beside the spatial location of Shopping Centers (left pane), this plot also displays the distribution of those points by their size in terms of square footage (right pane).
Figure B shows a second class example plot of the same area but now displaying a choropleth map of the distribution of the Median Household Income.
Figure 1, then combines the mapping tools in Figures A and B to display the spatial distribution of poverty at the Census Block level for Mecklenburg County in North Carolina. As it can be seen from the image, the distribution of census blocks with high levels of poverty are also those with the lowest levels of income levels in figure B, confirming this well-known relationship between income and poverty.
Introduction: This section goes deeper into the plotting R functions for spatial data. In particular, both shape files and raster data are combined into displays. In particular useful tips to determine how to plot raster data were implemented in this section.
Figure 2.1 and Figure 2.2 show the functionality of combining shape file and raster objects. The former displays the raster of the City of Champaign, plotted into the extent of those parcels deemed as vacant. The latter does the same, but focusing on the building footprint data in the Garden Hills neighborhood. Some R code has been left out on purpose to provide clarity on what options were used to obtain the final plots
Figure 3 shows an interactive web map that replicates the Lab example but for the State of Florida. I was personally interested in this results, since is ussually expected that a candidate that run in his “home state” will win the state. The oposite was actually true, since Marco rubio (U.S. Senator for the State of Florida) lost his state to Donald Drumpf.
This output was generated using R-Marckdown. The code has been attached
Figure A. Two-pane plot of Shopping Centers in Mecklenburg County, NC
Figure B. Spatial Distribution of the Median Household Income by Census Blocks in Mecklenburg County, NC
Figure 1. Spatial Distribution of the Poverty Rate by Census Blocks in Mecklenburg County, NC
Figure 2.1. Fixing the Extent on the Spatial Data Frame ‘parcels.vacant’
plotRGB(doq.1, r=3, g=2, b=1, ext=bbox(parcels.vacant.utm))
plot(parcels.vacant.utm, col="red", add=TRUE)
Figure 2.2. Fixing the Extent on the Spatial Data Frame ‘footprints’
plotRGB(doq.1, r=3, g=2, b=1, ext=bbox(res.footprints.utm))
plot(res.footprints.utm, add=TRUE)
Figure 3. Web Interactive Map for Spatial Voting Results in Florida
# Basic interactive map showing winner in each county:
leaflet(flmap) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(stroke=TRUE,
weight=1,
smoothFactor = 0.2,
fillOpacity = .75,
popup=flpopup,
color= ~winnerPalette(flmap@data$winner),
group="Winners"
) %>%
addLegend(position="bottomleft", colors=c("#984ea3", "#e41a1c"), labels=c("Trump", "Rubio"))