usadatafilecsv <- "Nutrition__Physical_Activity__and_Obesity_-_Youth_Risk_Behavior_Surveillance_System.csv"
usashapefile <-"cb_2014_us_state_5m/cb_2014_us_state_5m.shp"
mdfipscode <- "24"
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'purrr' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.0 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.1 ✔ tibble 3.1.8
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(tmap)
## Warning: package 'tmap' was built under R version 4.2.3
library(tmaptools)
## Warning: package 'tmaptools' was built under R version 4.2.3
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.2.3
library(sf)
## Warning: package 'sf' was built under R version 4.2.3
## Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(leaflet.extras)
## Warning: package 'leaflet.extras' was built under R version 4.2.3
library(dplyr)
library(rio)
## Warning: package 'rio' was built under R version 4.2.3
library(sp)
## Warning: package 'sp' was built under R version 4.2.3
setwd("C:/Users/aline/Downloads/New folder Project 2 NEW")
usadata <- import(usadatafilecsv)
mddata <- usadata %>%
filter(LocationDesc =="Maryland")
mddata1 <- mddata[,c("Class", "Grade", "Sample_Size", "High_Confidence_Limit")]
setwd("C:/Users/aline/Downloads/New folder Project 2 NEW")
library(raster)
## Warning: package 'raster' was built under R version 4.2.3
##
## Attaching package: 'raster'
## The following object is masked from 'package:dplyr':
##
## select
library(rgdal)
## Warning: package 'rgdal' was built under R version 4.2.3
## Please note that rgdal will be retired during 2023,
## plan transition to sf/stars/terra functions using GDAL and PROJ
## at your earliest convenience.
## See https://r-spatial.org/r/2022/04/12/evolution.html and https://github.com/r-spatial/evolution
## rgdal: version: 1.6-5, (SVN revision 1199)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.5.2, released 2022/09/02
## Path to GDAL shared files: C:/Users/aline/AppData/Local/R/win-library/4.2/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ runtime: Rel. 8.2.1, January 1st, 2022, [PJ_VERSION: 821]
## Path to PROJ shared files: C:/Users/aline/AppData/Local/R/win-library/4.2/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.6-0
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
usgeo <- shapefile("cb_2014_us_state_5m/cb_2014_us_state_5m.shp")
## Warning: [vect] Z coordinates ignored
qtm(usgeo)

mdgeo <- usgeo[usgeo$STATEFP==24,] #24 mdcode
qtm(mdgeo)

str(mdgeo)
## Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
## ..@ data :'data.frame': 1 obs. of 9 variables:
## .. ..$ STATEFP : chr "24"
## .. ..$ STATENS : chr "01714934"
## .. ..$ AFFGEOID: chr "0400000US24"
## .. ..$ GEOID : chr "24"
## .. ..$ STUSPS : chr "MD"
## .. ..$ NAME : chr "Maryland"
## .. ..$ LSAD : chr "00"
## .. ..$ ALAND : int -622228556
## .. ..$ AWATER : int -1606479367
## ..@ polygons :List of 1
## .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
## .. .. .. ..@ Polygons :List of 4
## .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
## .. .. .. .. .. .. ..@ labpt : num [1:2] -76 38
## .. .. .. .. .. .. ..@ area : num 0.00484
## .. .. .. .. .. .. ..@ hole : logi FALSE
## .. .. .. .. .. .. ..@ ringDir: int 1
## .. .. .. .. .. .. ..@ coords : num [1:21, 1:2] -76 -76 -76 -76 -76 ...
## .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
## .. .. .. .. .. .. .. .. ..$ : chr [1:21] "16694" "16695" "16696" "16697" ...
## .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
## .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
## .. .. .. .. .. .. ..@ labpt : num [1:2] -76.1 38.1
## .. .. .. .. .. .. ..@ area : num 0.00665
## .. .. .. .. .. .. ..@ hole : logi FALSE
## .. .. .. .. .. .. ..@ ringDir: int 1
## .. .. .. .. .. .. ..@ coords : num [1:36, 1:2] -76.1 -76.1 -76.1 -76.1 -76.1 ...
## .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
## .. .. .. .. .. .. .. .. ..$ : chr [1:36] "16715" "16716" "16717" "16718" ...
## .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
## .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
## .. .. .. .. .. .. ..@ labpt : num [1:2] -76.4 38.8
## .. .. .. .. .. .. ..@ area : num 0.000878
## .. .. .. .. .. .. ..@ hole : logi FALSE
## .. .. .. .. .. .. ..@ ringDir: int 1
## .. .. .. .. .. .. ..@ coords : num [1:9, 1:2] -76.4 -76.4 -76.4 -76.4 -76.4 ...
## .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
## .. .. .. .. .. .. .. .. ..$ : chr [1:9] "16751" "16752" "16753" "16754" ...
## .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
## .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
## .. .. .. .. .. .. ..@ labpt : num [1:2] -76.8 39
## .. .. .. .. .. .. ..@ area : num 2.79
## .. .. .. .. .. .. ..@ hole : logi FALSE
## .. .. .. .. .. .. ..@ ringDir: int 1
## .. .. .. .. .. .. ..@ coords : num [1:1647, 1:2] -79.5 -79.5 -79.5 -79.5 -79.5 ...
## .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
## .. .. .. .. .. .. .. .. ..$ : chr [1:1647] "16760" "16761" "16762" "16763" ...
## .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
## .. .. .. ..@ plotOrder: int [1:4] 4 2 1 3
## .. .. .. ..@ labpt : num [1:2] -76.8 39
## .. .. .. ..@ ID : chr "12"
## .. .. .. ..@ area : num 2.8
## ..@ plotOrder : int 1
## ..@ bbox : num [1:2, 1:2] -79.5 37.9 -75 39.7
## .. ..- attr(*, "dimnames")=List of 2
## .. .. ..$ : chr [1:2] "x" "y"
## .. .. ..$ : chr [1:2] "min" "max"
## ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
## .. .. ..@ projargs: chr "+proj=longlat +datum=NAD83 +no_defs"
## .. .. ..$ comment: chr "GEOGCRS[\"unknown\",\n DATUM[\"North American Datum 1983\",\n ELLIPSOID[\"GRS 1980\",6378137,298.2572"| __truncated__
## ..$ comment: chr "FALSE"