Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 如何使用传单R绘制基于国家的合唱团_Json_R_Leaflet_Geospatial - Fatal编程技术网

Json 如何使用传单R绘制基于国家的合唱团

Json 如何使用传单R绘制基于国家的合唱团,json,r,leaflet,geospatial,Json,R,Leaflet,Geospatial,World Bounders geo.json从此处下载 我试图突出显示3个国家(在世界地图视图中),并根据该国的项目数量以渐变色绘制它们 以下是我的步骤: 首先下载world boundary geo.json文件作为底图读取; 然后我尝试突出显示数据中的国家多边形。然而事实证明,世界上所有的国家都被这三个国家的信息涂上了颜色和标签。这是地理数据帧子集设置问题吗 WorldCountry <-geojsonio::geojson_read("./GeoData/countries.geo

World Bounders geo.json从此处下载

我试图突出显示3个国家(在世界地图视图中),并根据该国的项目数量以渐变色绘制它们

以下是我的步骤:

首先下载world boundary geo.json文件作为底图读取; 然后我尝试突出显示数据中的国家多边形。然而事实证明,世界上所有的国家都被这三个国家的信息涂上了颜色和标签。这是地理数据帧子集设置问题吗

WorldCountry <-geojsonio::geojson_read("./GeoData/countries.geo.json", what = "sp")

#Dataframe for choropleth map
Country <- c("Bulgaria","Pakistan","Turkey")
Projects <- c(2,1,6)
data <- data.frame(Country,Projects)

#basemap
Map <- leaflet(WorldCountry) %>% addTiles() %>% addPolygons()

#set bin and color for choropleth map
bins <- c(0,1,2,3,4,5,6,7,8,9,10,Inf)
pal <- colorBin("YlOrRd", domain = data$Projects, bins = bins)

#set labels
labels <- sprintf(
  "<strong>%s</strong><br/>%g projects <sup></sup>",
  data$Country, data$Projects) %>% lapply(htmltools::HTML)

#add polygons,labels and mouse over effect
Map %>% addPolygons(
  fillColor = ~pal(data$Projects),
  weight = 2,
  opacity = 1,
  color = 'white',
  dashArray = '3',
  fillOpacity = 0.7,
  highlight = highlightOptions(
     weight = 5,
    color = "#666",
    dashArray = "",
    fillOpacity = 0.7,
    bringToFront = TRUE),
  label = labels,
  labelOptions = labelOptions(
    style = list("font-weight" = "normal", padding = "3px 8px"),
    textsize = "15px",
    direction = "auto")
)
WorldCountry%lappy(htmltools::HTML)
#添加多边形、标签和鼠标悬停效果
映射%>%addPolygons(
fillColor=~pal(数据$Projects),
重量=2,
不透明度=1,
颜色='白色',
dashArray='3',
fillOpacity=0.7,
highlight=highlightOptions(
重量=5,
color=“#666”,
dashArray=“”,
fillOpacity=0.7,
bringToFront=真),
标签=标签,
标签选项=标签选项(
样式=列表(“font-weight”=“normal”,padding=“3px 8px”),
textsize=“15px”,
方向=“自动”)
)
我期待着这样的事情:


这样就可以了!使用以下方法对WorldCountry进行子集划分:

data_Map <- WorldCountry[WorldCountry$id %in% data$Country, ]
Map <- leaflet(data_Map) %>% addTiles() %>% addPolygons()
data\u映射%addPolygons()

子集将包含WorldCountry$name

data_Map <- WorldCountry[WorldCountry$name %in% data$Country, ]

Map <- leaflet(data_Map) %>% addTiles() %>% addPolygons(
  fillColor = ~pal(data$Projects),
  weight = 2,
  opacity = 1,
  color = 'white',
  dashArray = '3',
  fillOpacity = 0.7,
  highlight = highlightOptions(
    weight = 5,
    color = "#666",
    dashArray = "",
    fillOpacity = 0.7,
    bringToFront = TRUE),
  label = labels,
  labelOptions = labelOptions(
    style = list("font-weight" = "normal", padding = "3px 8px"),
    textsize = "15px",
    direction = "auto")
)
数据\u映射%addPolygons(
fillColor=~pal(数据$Projects),
重量=2,
不透明度=1,
颜色='白色',
dashArray='3',
fillOpacity=0.7,
highlight=highlightOptions(
重量=5,
color=“#666”,
dashArray=“”,
fillOpacity=0.7,
bringToFront=真),
标签=标签,
标签选项=标签选项(
样式=列表(“font-weight”=“normal”,padding=“3px 8px”),
textsize=“15px”,
方向=“自动”)
)