-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMaps_making.Rmd
69 lines (58 loc) · 1.92 KB
/
Maps_making.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
title: "Making map"
author: "Uyen Nguyen"
date: "12/7/2017"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r libraries}
library(ncdf4)
library(raster)
library(rasterVis)
library(maptools)
library(rgdal)
library(dplyr)
library(reshape2)
library (rgdal)
library(sp)
library(mapview)
library(leaflet)
```
```{r Processing spatial data}
# Import shape file of coastal counties
county_sp <- readOGR("/home/shares/oss2017/social/DATA/counties.coast.shp")
# Import master dataset
data <- read.csv("/home/shares/oss2017/social/DATA/trunc_master_data.csv")
# Group data by year
Soci_year <- subset(data, data$year %in% 2010)
# Binding data to shape file using ALAND as the unique ID for merging
Soci_year_sp <- merge(county_sp,Soci_year, by.x="ALAND", by.y="ALAND")
#Convert Population density from factor to numeric
Soci_year_sp$Pop_Density_per_sq_.mile <- as.numeric(Soci_year_sp$Pop_Density_per_sq_.mile)
#Plot map for social bridge 2010
#Create color quantile palette
pal <- colorNumeric(palette = "YlOrRd",
domain = Soci_year_sp$SoCI_bridge)
#Create pop up for map (optional)
#popup = paste0("<strong>County- </strong>", Soci_year$NAME,": ",format(round(as.numeric(Soci_year$SoCI_bridge),4),nsmall=4))
#Create leaflet map for Social bridging
map <- leaflet(Soci_year_sp) %>%
addTiles() %>%
addPolygons(color = "#444444", weight = 1, smoothFactor = 0.5,
opacity = 1.0, fillOpacity = 0.5,
fillColor = ~colorQuantile("YlOrRd",SoCI_bridge)(SoCI_bridge),
#popup = popup,
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE)) %>%
addLegend("topright",
pal = pal,
values = ~SoCI_bridge,
title = "Social Bridging",
opacity = 1
)
map
```