Introduction

In this assignment I used the database was token from maine.gov website .I combain some date and put all the variables in one file to make it easy to manipulate and graph it .The data included the countries of Maine ,median Household Income ,Population rate of health , Total Enroll School and (long & lat).

 

Methodology

Downloaded the shapefiles from the Maine Office of GIS Data Catalog

Then read the in shapefiles from Maine data using reasORG 
 

library(ggmap)
## Loading required package: ggplot2
library(ggplot2)
library(leaflet)
library(rgdal)
## Warning: package 'rgdal' was built under R version 3.4.2
## Loading required package: sp
## rgdal: version: 1.2-13, (SVN revision 686)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.1.3, released 2017/20/01
##  Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rgdal/gdal
##  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
##  Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rgdal/proj
##  Linking to sp version: 1.2-5
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.4.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
ME_Counties <- readOGR("./maineCounties", "Cnty24P_Dissolve" , stringsAsFactors = FALSE)
## OGR data source with driver: ESRI Shapefile 
## Source: "./maineCounties", layer: "Cnty24P_Dissolve"
## with 16 features
## It has 3 fields
## [1] "COUNTY"     "Shape_area" "Shape_len"
ME_Counties <- spTransform(ME_Counties, CRS("+proj=longlat +datum=WGS84"))

leaflet() %>% 
  addProviderTiles("CartoDB.Positron") %>% 
  addPolygons(data = ME_Counties,
              popup = ~COUNTY)
library(dplyr)
library(leaflet)
ME_ICOME <- read.csv("maineData.csv", stringsAsFactors = FALSE)
ME_ICOME_COUNTIES <- merge(ME_Counties, ME_ICOME, by.x="COUNTY", by.y="County")
COUNTY_POPUP <- paste("<strong>County: </strong>",
                      ME_ICOME_COUNTIES$COUNTY,
                      "<br><strong> INCOME ($) </strong>",
                      ME_ICOME_COUNTIES$INCOME,
                      "<br><strong>Total Population (N): </strong>",
                      ME_ICOME_COUNTIES$POPULATION)

pal <- colorNumeric("Greens", NULL)


leaflet(data = ME_ICOME_COUNTIES) %>%
  addProviderTiles("CartoDB.Positron") %>% 
  addPolygons(fillColor = ~pal(INCOME),
              color = "#000000",
              weight = 1.5,
              popup = ~COUNTY_POPUP) %>%
  addLegend(pal = pal, 
            values = ~INCOME, 
            opacity = 1.5, 
            title = "Median Household Income($)", 
            position = "bottomright")
## Warning in doColorRamp(colorMatrix, x, alpha, ifelse(is.na(na.color), "", :
## '.Random.seed' is not an integer vector but of type 'NULL', so ignored
ME_ICOME_COUNTIES <- merge(ME_Counties, ME_ICOME, by.x="COUNTY", by.y="County")
COUNTY_POPUP <- paste("<strong>County: </strong>",
                      ME_ICOME_COUNTIES$COUNTY,
                      "<br><strong> INCOME ($) </strong>",
                      ME_ICOME_COUNTIES$INCOME,
                      "<br><strong>Total Population (N): </strong>",
                      ME_ICOME_COUNTIES$POPULATION)

pal <- colorNumeric("Greens", NULL)


leaflet(data = ME_ICOME_COUNTIES) %>%
  addProviderTiles("CartoDB.Positron") %>% 
  addTiles() %>%
  addMarkers(~long, ~lat, popup = ~paste("<h3>County: </h3>",COUNTY  , "<br>", "<strong>POPULATION (N):</strong>" , POPULATION ,"<br>" , "<strong>INCOME($):</strong>",INCOME ,"<br>","<strong>Health Rate (%):</strong>",Health.Rate ,"<br>","<strong>Total.Enroll.School (N):</strong>" ,Total.Enroll.School,spe="  ")) %>%
  addPolygons(fillColor = ~pal(INCOME),
              color = "#000000",
              weight = 1.5,
              popup = ~COUNTY_POPUP) %>%
  addLegend(pal = pal, 
            values = ~INCOME, 
            opacity = 1.5, 
            title = "Median Household Income($)", 
            position = "bottomright")
COUNTY_POPUP <- paste("<strong>County: </strong>",
                      ME_ICOME_COUNTIES$COUNTY,
                      "<br><strong> INCOME ($) </strong>",
                      ME_ICOME_COUNTIES$INCOME,
                      "<br><strong>Total Population (N): </strong>",
                      ME_ICOME_COUNTIES$POPULATION)

pal <- colorNumeric("Blues", NULL)


leaflet(data = ME_ICOME_COUNTIES) %>%
  addProviderTiles("CartoDB.Positron") %>% 
  addPolygons(fillColor = ~pal(POPULATION),
              color = "#000000",
              weight = 1.5,
              popup = ~COUNTY_POPUP) %>%
  addLegend(pal = pal, 
            values = ~POPULATION, 
            opacity = 1.5, 
            title = "Total Population(N)", 
            position = "bottomright")
COUNTY_POPUP <- paste("<strong>County: </strong>",
                      ME_ICOME_COUNTIES$COUNTY,
                      "<br><strong> INCOME ($) </strong>",
                      ME_ICOME_COUNTIES$INCOME,
                      "<br><strong>Total Population (N): </strong>",
                      ME_ICOME_COUNTIES$Health.Rate,"%")

pal <- colorNumeric("Reds", NULL)


leaflet(data = ME_ICOME_COUNTIES) %>%
  addProviderTiles("CartoDB.Positron") %>% 
  addPolygons(fillColor = ~pal(Health.Rate),
              color = "#000000",
              weight = 1.5,
              popup = ~COUNTY_POPUP) %>%
  addLegend(pal = pal, 
            values = ~Health.Rate, 
            opacity = 1.5, 
            title = "Health Rate(%)", 
            position = "bottomright")