使用rCharts和基于点要素的传单缩放的圆圈

时间:2015-02-25 16:19:47

标签: r gis leaflet rcharts

我使用rChartsLeaflet制作了带有标记的地图,代码如下。

library(rCharts)
df <- data.frame(location = c("White House", "Impound Lot", "Bush Garden", "Rayburn", "Robertson House", "Beers Elementary"), latitude = c(38.89710, 38.81289, 38.94178, 38.8867787, 38.9053894, 38.86466), longitude = c(-77.036545, -77.0171983, -77.073311, -77.0105317, -77.0616441, -76.95554), capacity = c(30, 48, 2, 80, 5, 18))
df
          location latitude longitude capacity
1      White House 38.89710 -77.03655       30
2      Impound Lot 38.81289 -77.01720       48
3      Bush Garden 38.94178 -77.07331        2
4          Rayburn 38.88678 -77.01053       80
5  Robertson House 38.90539 -77.06164        5
6 Beers Elementary 38.86466 -76.95554       18

map <- Leaflet$new()
map$setView(c(38.89710, -77.03655), 12)
map$tileLayer(provider = 'Stamen.TonerLite')
for (i in 1:nrow(df)) {
  map$marker(c(df[i, "latitude"], df[i, "longitude"]), bindPopup = df[i, "location"])
}
print(map)

我现在很有兴趣将一个圆圈缩放到df$capacity而不是标记。我试图用map$marker替换map$circle,但没有运气。

this的某些内容正是我想要实现的目标。

1 个答案:

答案 0 :(得分:1)

无法使用rMaps(已经替换地图的rCharts),但我得到了'传单'包工作......

devtools::install_github("rstudio/leaflet")
library(leaflet)
leaflet() %>% 
  addTiles(urlTemplate="http://{s}.tile.stamen.com/toner-lite/{z}/{x}/{y}.png") %>% 
  setView(-77.03655, 38.89710, zoom = 12) %>% 
  addCircles(data = df, lat = ~ latitude, lng = ~ longitude, radius = ~ capacity)