0
여러분, 도대체 무슨 일이 벌어지고 있는지 잘 모릅니다. 나는 전에 충분한 전단지를 만들었고 그런 문제가 없었습니다. 조금 충격을 받았다. 매우 간단한 작업. 리플렛 맵에 csv 및 json 파일을 병합합니다 - 이상한 실수
이 결과 ... 상태로
# US Adult Obesity 2016
library(rgdal)
library(sp)
library(leaflet)
library(geojsonio)
library(RColorBrewer)
library(dplyr)
# Set working directory
setwd("C:/~/App US Adult Obesity")
# Read csv
obesity <- read.csv("US Adult Obesity.csv", header = TRUE)
# Read geojson file
states <- geojson_read("gz_2010_us_040_00_500k.json", what = "sp")
View(states)
# Match data
obesity.map.2016 <- merge(states, obesity, by.x = "NAME", by.y = "State")
class(obesity.map.2016)
View(obesity.map.2016)
# Create a palette
obesity$Year.2016 <- as.numeric(as.character(obesity$Year.2016))
pal <- colorBin("Reds", c(22, 38), na.color = "#808080")
#, alpha = FALSE, reverse = FALSE)
# Create a popup
state_popup <- paste0("<strong>State: </strong>",
obesity$state,
"<br><strong>% of adult obesity in 2016: </strong>",
obesity$Year.2016)
# Create a map
leaflet(obesity.map.2016) %>%
addProviderTiles(providers$Stamen.TonerLite) %>%
setView(lng = -98.583, lat = 39.833, zoom = 4) %>%
addPolygons(color = "#444444", weight = 1,
# opacity = 0.5,
fillOpacity = 0.7,
fillColor = ~pal(obesity$Year.2016),
popup = state_popup) %>%
addLegend("bottomright", pal = pal, values = ~obesity$Year.2016,
opacity = 1,
title = "US Adult Obesity in 2016 by State")
을 .csv 및 .json 파일과 일치하지 수, 나는 캘리포니아에서 미네소타 데이터를 가지고있다. 보기가 일치하지 않는다고 나에게 50 개의 주 + DC가 있습니다. 어떻게하는지 잊어 버렸습니다. 내 바보 같은 실수에 대한 암시가 있습니까?