我已使用以下代码构建了一个chloropleth贴图。目的是使不同国家的负载显示为不同的绿色阴影(较暗的颜色,其中医疗保健支出占GDP的比例更大)。但是,当我运行此代码时,会生成一张世界地图,其中只有澳大利亚带有绿色。似乎没有其他国家会改变。澳大利亚是我数据框中的第一个国家,所以我认为这与问题有关。
# individual mapping exercise
library(readxl)
library(leaflet)
library(rgdal)
# import the dataset
health_eur <- read_excel("healthcare_expediture.xlsx")
# import shp
world <- readOGR("TM_WORLD_BORDERS_SIMPL-0.3/TM_WORLD_BORDERS_SIMPL-
0.3.shp")
# align entries in each dataset
is.element(health_eur$country, world$NAME)
health_eur$country[16] <- "Ireland"
health_eur$country[30] <- "Slovakia"
health_eur$country[27] <- "Korea, Republic of"
is.element(world$NAME, health_eur$country)
world <- subset(world, is.element(world$NAME, health_eur$country))
# move one vector around so they are in the same order
health_eur$country <- with(health_eur,
health_eur[order(health_eur$country),])
# create bins and colour palette
bins <- c(2.5, 5.0, 7.5, 10.0, 12.5, 15.0, 17.5, 20.0)
pal <- colorBin("Greens", domain = health_eur$health_exp, bins = bins)
# create chloropleth
map <- leaflet() %>%
setView(0,0,0) %>%
addProviderTiles(providers$Stamen.Toner) %>%
addPolygons( data = world,
smoothFactor = 0.5,
color = "f6f6f6",
fillOpacity = 0.95,
fillColor = ~pal(health_eur$health_exp),
highlight = highlightOptions(
weight = 7,
color = "#304ffe",
dashArray = "",
bringToFront = TRUE
))
map
这是生成的地图:
答案 0 :(得分:0)
可以解决从dashArray = ""
删除highlightOptions
的问题。
map <- leaflet() %>%
setView(0,0,0) %>%
addProviderTiles(providers$Stamen.Toner) %>%
addPolygons( data = world,
smoothFactor = 0.5,
color = "f6f6f6",
fillOpacity = 0.95,
fillColor = ~pal(health_eur$health_exp),
highlightOptions = highlightOptions(
weight = 2,
color = "#304ffe",
bringToFront = TRUE
))
map