Advertisement
Guest User

example map partial code

a guest
Mar 31st, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. # As of this point in my code ...
  2. #### 3. GENERATE AND SAVE MAPS ####
  3.  
  4. map.data.march28 <- map_panel[date == '2020-03-28', .(GEO_ID, date, bin_cases)]
  5. class(map.data.march28)
  6. map.data.march28
  7.  
  8. class(county.sf)
  9. county.sf
  10.  
  11. merged.map.data <- merge(county.sf, map.data.march28, by = 'GEO_ID')
  12. class(merged.map.data)
  13. merged.map.data
  14.  
  15. merged.map.data2 <- merge(map.data.march28, county.sf, by = 'GEO_ID')
  16. class(merged.map.data2)
  17. merged.map.data2
  18.  
  19. ggplot(merged.map.data) + geom_sf(aes(fill = bin_cases))
  20. ggplot(merged.map.data2) + geom_sf(aes(fill = bin_cases))
  21.  
  22.  
  23. ## OUTPUT ##
  24.  
  25. > # As of this point in my code ...
  26. > #### 3. GENERATE AND SAVE MAPS ####
  27. >
  28. > map.data.march28 <- map_panel[date == '2020-03-28', .(GEO_ID, date, bin_cases)]
  29. > class(map.data.march28)
  30. [1] "data.table" "data.frame"
  31. > map.data.march28
  32. GEO_ID date bin_cases
  33. 1: 0500000US01001 2020-03-28 B3
  34. 2: 0500000US01003 2020-03-28 B2
  35. 3: 0500000US01005 2020-03-28 B1
  36. 4: 0500000US01007 2020-03-28 B1
  37. 5: 0500000US01009 2020-03-28 B2
  38. ---
  39. 3103: 0500000US56037 2020-03-28 B2
  40. 3104: 0500000US56039 2020-03-28 B3
  41. 3105: 0500000US56041 2020-03-28 B1
  42. 3106: 0500000US56043 2020-03-28 B3
  43. 3107: 0500000US56045 2020-03-28 B1
  44. >
  45. > class(county.sf)
  46. [1] "sf" "data.frame"
  47. > county.sf
  48. Simple feature collection with 3108 features and 1 field
  49. geometry type: MULTIPOLYGON
  50. dimension: XY
  51. bbox: xmin: -124.7332 ymin: 24.5447 xmax: -66.9499 ymax: 49.38436
  52. epsg (SRID): 4269
  53. proj4string: +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs
  54. First 10 features:
  55. GEO_ID geometry
  56. 5 0500000US04003 MULTIPOLYGON (((-109.0476 3...
  57. 6 0500000US04009 MULTIPOLYGON (((-110.0006 3...
  58. 7 0500000US04012 MULTIPOLYGON (((-114.5165 3...
  59. 8 0500000US04015 MULTIPOLYGON (((-114.0506 3...
  60. 9 0500000US04023 MULTIPOLYGON (((-111.164 31...
  61. 10 0500000US05005 MULTIPOLYGON (((-92.52913 3...
  62. 11 0500000US05023 MULTIPOLYGON (((-92.24052 3...
  63. 12 0500000US05025 MULTIPOLYGON (((-92.33425 3...
  64. 13 0500000US05027 MULTIPOLYGON (((-92.98871 3...
  65. 14 0500000US05037 MULTIPOLYGON (((-90.50299 3...
  66. >
  67. > merged.map.data <- merge(county.sf, map.data.march28, by = 'GEO_ID')
  68. > class(merged.map.data)
  69. [1] "sf" "data.frame"
  70. > merged.map.data
  71. Simple feature collection with 3107 features and 3 fields
  72. geometry type: MULTIPOLYGON
  73. dimension: XY
  74. bbox: xmin: -124.7332 ymin: 24.5447 xmax: -66.9499 ymax: 49.38436
  75. epsg (SRID): 4269
  76. proj4string: +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs
  77. First 10 features:
  78. GEO_ID date bin_cases geometry
  79. 1 0500000US01001 2020-03-28 B3 MULTIPOLYGON (((-86.91759 3...
  80. 2 0500000US01003 2020-03-28 B2 MULTIPOLYGON (((-87.59893 3...
  81. 3 0500000US01005 2020-03-28 B1 MULTIPOLYGON (((-85.12563 3...
  82. 4 0500000US01007 2020-03-28 B1 MULTIPOLYGON (((-87.4212 32...
  83. 5 0500000US01009 2020-03-28 B2 MULTIPOLYGON (((-86.37753 3...
  84. 6 0500000US01011 2020-03-28 B3 MULTIPOLYGON (((-85.41024 3...
  85. 7 0500000US01013 2020-03-28 B2 MULTIPOLYGON (((-86.9069 31...
  86. 8 0500000US01015 2020-03-28 B2 MULTIPOLYGON (((-86.14556 3...
  87. 9 0500000US01017 2020-03-28 B3 MULTIPOLYGON (((-85.23238 3...
  88. 10 0500000US01019 2020-03-28 B2 MULTIPOLYGON (((-85.84362 3...
  89. >
  90. > merged.map.data2 <- merge(map.data.march28, county.sf, by = 'GEO_ID')
  91. > class(merged.map.data2)
  92. [1] "data.table" "data.frame"
  93. > merged.map.data2
  94. GEO_ID date bin_cases geometry
  95. 1: 0500000US01001 2020-03-28 B3 <XY>
  96. 2: 0500000US01003 2020-03-28 B2 <XY>
  97. 3: 0500000US01005 2020-03-28 B1 <XY>
  98. 4: 0500000US01007 2020-03-28 B1 <XY>
  99. 5: 0500000US01009 2020-03-28 B2 <XY>
  100. ---
  101. 3103: 0500000US56037 2020-03-28 B2 <XY>
  102. 3104: 0500000US56039 2020-03-28 B3 <XY>
  103. 3105: 0500000US56041 2020-03-28 B1 <XY>
  104. 3106: 0500000US56043 2020-03-28 B3 <XY>
  105. 3107: 0500000US56045 2020-03-28 B1 <XY>
  106. >
  107. > ggplot(merged.map.data) + geom_sf(aes(fill = bin_cases)) # Maps fine
  108. > ggplot(merged.map.data2) + geom_sf(aes(fill = bin_cases)) # Identical map
  109. >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement