kar*_*2k2 11 maps r leaflet ggmap r-leaflet
我试图显示给定位置的各个点,就像相当于点图的地图。我尝试使用leafletR 中的库,但我只能将标记的大小映射到连续变量。是否可以将各个数据点映射为簇,而不是将标记的大小映射到连续变量?
我的数据看起来像这样
Lat,Lon,Place,People
19.877263,75.3390241,Aurangabad,1
20.2602939,85.8394548,Bhubaneshwar,2
30.7194022,76.7646552,Chandigarh,23
13.0801721,80.2838331,Chennai,25
11.0018115,76.9628425,Coimbatore,2
27.4844597,94.9019447,Dibrugarh,1
16.2915189,80.4541588,Guntur,1
17.3887859,78.4610647,Hyderabad,4
22.5677459,88.3476023,Kolkata,7
15.8309251,78.0425373,Kurnool,1
9.9256493,78.1228866,Madurai,1
Run Code Online (Sandbox Code Playgroud)
Bap*_*Das 11
您可以使用以下代码来绘制点图
leaflet(df) %>% addTiles() %>%
addCircleMarkers(lng = ~Lon, lat = ~Lat,
popup = ~Place)
Run Code Online (Sandbox Code Playgroud)
df = structure(list(Lat = c(19.877263, 20.2602939, 30.7194022, 13.0801721,
11.0018115, 27.4844597, 16.2915189, 17.3887859, 22.5677459, 15.8309251,
9.9256493), Lon = c(75.3390241, 85.8394548, 76.7646552, 80.2838331,
76.9628425, 94.9019447, 80.4541588, 78.4610647, 88.3476023, 78.0425373,
78.1228866), Place = structure(1:11, .Label = c("Aurangabad",
"Bhubaneshwar", "Chandigarh", "Chennai", "Coimbatore", "Dibrugarh",
"Guntur", "Hyderabad", "Kolkata", "Kurnool", "Madurai"), class = "factor"),
People = c(1L, 2L, 23L, 25L, 2L, 1L, 1L, 4L, 7L, 1L, 1L)), class = "data.frame", row.names = c(NA,
-11L))
Run Code Online (Sandbox Code Playgroud)
leaflet与包配合使用效果很好sf。对数据点进行采样
lat <- c(19.877263, 20.2602939)
lon <- c(75.3390241, 85.8394548)
place <- c("Aurangabad", "Bhubaneshwar")
Run Code Online (Sandbox Code Playgroud)
您可以使用 package 将它们转换为空间对象sf。为了leaflet给你瓷砖,你需要有 WSG84 坐标。我假设你的数据在这个坐标系中。
library(sf)
df <- data.frame(lon, lat, place, stringsAsFactors = FALSE)
points <- st_as_sf(df, coords = c("lon", "lat"), crs = 4326)
Run Code Online (Sandbox Code Playgroud)
然后就很容易用 来绘图了leaflet。假设您希望标记在单击时弹出地点名称
library(leaflet)
leaflet(df) %>% addTiles() %>% addMarkers(popup = ~ place)
Run Code Online (Sandbox Code Playgroud)