Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # As of this point in my code ...
- #### 3. GENERATE AND SAVE MAPS ####
- map.data.march28 <- map_panel[date == '2020-03-28', .(GEO_ID, date, bin_cases)]
- class(map.data.march28)
- map.data.march28
- class(county.sf)
- county.sf
- merged.map.data <- merge(county.sf, map.data.march28, by = 'GEO_ID')
- class(merged.map.data)
- merged.map.data
- merged.map.data2 <- merge(map.data.march28, county.sf, by = 'GEO_ID')
- class(merged.map.data2)
- merged.map.data2
- ggplot(merged.map.data) + geom_sf(aes(fill = bin_cases))
- ggplot(merged.map.data2) + geom_sf(aes(fill = bin_cases))
- ## OUTPUT ##
- > # As of this point in my code ...
- > #### 3. GENERATE AND SAVE MAPS ####
- >
- > map.data.march28 <- map_panel[date == '2020-03-28', .(GEO_ID, date, bin_cases)]
- > class(map.data.march28)
- [1] "data.table" "data.frame"
- > map.data.march28
- GEO_ID date bin_cases
- 1: 0500000US01001 2020-03-28 B3
- 2: 0500000US01003 2020-03-28 B2
- 3: 0500000US01005 2020-03-28 B1
- 4: 0500000US01007 2020-03-28 B1
- 5: 0500000US01009 2020-03-28 B2
- ---
- 3103: 0500000US56037 2020-03-28 B2
- 3104: 0500000US56039 2020-03-28 B3
- 3105: 0500000US56041 2020-03-28 B1
- 3106: 0500000US56043 2020-03-28 B3
- 3107: 0500000US56045 2020-03-28 B1
- >
- > class(county.sf)
- [1] "sf" "data.frame"
- > county.sf
- Simple feature collection with 3108 features and 1 field
- geometry type: MULTIPOLYGON
- dimension: XY
- bbox: xmin: -124.7332 ymin: 24.5447 xmax: -66.9499 ymax: 49.38436
- epsg (SRID): 4269
- proj4string: +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs
- First 10 features:
- GEO_ID geometry
- 5 0500000US04003 MULTIPOLYGON (((-109.0476 3...
- 6 0500000US04009 MULTIPOLYGON (((-110.0006 3...
- 7 0500000US04012 MULTIPOLYGON (((-114.5165 3...
- 8 0500000US04015 MULTIPOLYGON (((-114.0506 3...
- 9 0500000US04023 MULTIPOLYGON (((-111.164 31...
- 10 0500000US05005 MULTIPOLYGON (((-92.52913 3...
- 11 0500000US05023 MULTIPOLYGON (((-92.24052 3...
- 12 0500000US05025 MULTIPOLYGON (((-92.33425 3...
- 13 0500000US05027 MULTIPOLYGON (((-92.98871 3...
- 14 0500000US05037 MULTIPOLYGON (((-90.50299 3...
- >
- > merged.map.data <- merge(county.sf, map.data.march28, by = 'GEO_ID')
- > class(merged.map.data)
- [1] "sf" "data.frame"
- > merged.map.data
- Simple feature collection with 3107 features and 3 fields
- geometry type: MULTIPOLYGON
- dimension: XY
- bbox: xmin: -124.7332 ymin: 24.5447 xmax: -66.9499 ymax: 49.38436
- epsg (SRID): 4269
- proj4string: +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs
- First 10 features:
- GEO_ID date bin_cases geometry
- 1 0500000US01001 2020-03-28 B3 MULTIPOLYGON (((-86.91759 3...
- 2 0500000US01003 2020-03-28 B2 MULTIPOLYGON (((-87.59893 3...
- 3 0500000US01005 2020-03-28 B1 MULTIPOLYGON (((-85.12563 3...
- 4 0500000US01007 2020-03-28 B1 MULTIPOLYGON (((-87.4212 32...
- 5 0500000US01009 2020-03-28 B2 MULTIPOLYGON (((-86.37753 3...
- 6 0500000US01011 2020-03-28 B3 MULTIPOLYGON (((-85.41024 3...
- 7 0500000US01013 2020-03-28 B2 MULTIPOLYGON (((-86.9069 31...
- 8 0500000US01015 2020-03-28 B2 MULTIPOLYGON (((-86.14556 3...
- 9 0500000US01017 2020-03-28 B3 MULTIPOLYGON (((-85.23238 3...
- 10 0500000US01019 2020-03-28 B2 MULTIPOLYGON (((-85.84362 3...
- >
- > merged.map.data2 <- merge(map.data.march28, county.sf, by = 'GEO_ID')
- > class(merged.map.data2)
- [1] "data.table" "data.frame"
- > merged.map.data2
- GEO_ID date bin_cases geometry
- 1: 0500000US01001 2020-03-28 B3 <XY>
- 2: 0500000US01003 2020-03-28 B2 <XY>
- 3: 0500000US01005 2020-03-28 B1 <XY>
- 4: 0500000US01007 2020-03-28 B1 <XY>
- 5: 0500000US01009 2020-03-28 B2 <XY>
- ---
- 3103: 0500000US56037 2020-03-28 B2 <XY>
- 3104: 0500000US56039 2020-03-28 B3 <XY>
- 3105: 0500000US56041 2020-03-28 B1 <XY>
- 3106: 0500000US56043 2020-03-28 B3 <XY>
- 3107: 0500000US56045 2020-03-28 B1 <XY>
- >
- > ggplot(merged.map.data) + geom_sf(aes(fill = bin_cases)) # Maps fine
- > ggplot(merged.map.data2) + geom_sf(aes(fill = bin_cases)) # Identical map
- >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement