在R中将颜色更改为小叶多边形

时间:2017-11-08 11:55:01

标签: r leaflet mapzen

我正在尝试使用传单 Mapzen 更改绘制的多边形的颜色。使用当前图块清晰可见颜色,但与其他图块不同,例如addTiles()。 我应该如何更改三个多边形的参数?

要使代码生效,您必须输入mapzen键。

library(rmapzen)
library(leaflet)

Sys.setenv(MAPZEN_KEY = "mapzen-******")
#https://tarakc02.github.io/rmapzen/#introduction

ucb <- mz_geocode("Via Giovanni Spadolini 7, Milan, Italy")

isos <- mz_isochrone(
  ucb,
  costing_model = mz_costing$auto(),
  contours = mz_contours(c(5, 10, 15)),
  polygons = TRUE
)

leaflet(as_sp(isos)) %>%

 addProviderTiles("CartoDB.DarkMatter") %>%

 addPolygons(color = ~color, weight = 1) %>%

 addLegend(colors = ~color, 
        labels = ~paste(contour, "minutes"),
            title = "Drive times from <br/> Centro Leoni")

1 个答案:

答案 0 :(得分:0)

我意识到应该单独添加多边形而不是:

leaflet(as_sp(isos))

解决方案:

iso10 <- as_sp(mz_isochrone(
  ucb,
  costing_model = mz_costing$auto(),
  contours = mz_contours(10),
  polygons = TRUE
))
iso30 <- as_sp(mz_isochrone(
  ucb,
  costing_model = mz_costing$auto(),
  contours = mz_contours(30),
  polygons = TRUE
))
iso60 <- as_sp(mz_isochrone(
  ucb,
  costing_model = mz_costing$auto(),
  contours = mz_contours(60),
  polygons = TRUE
))

m = leaflet() %>%
  addProviderTiles("CartoDB.DarkMatter") %>%
  addPolygons(data = iso10, color = "red", fillColor = "red")%>%
  addPolygons(data = iso30, color = "green", fillColor = "green")%>%
  addPolygons(data = iso60, color = "blue", fillColor = "blue")