简体   繁体   English

使用传单 lib 在地图上绘制 34 个点

[英]using leaflet lib to plot 34 points on map

I have a dataset of 34 rows and 3 columns.我有一个 34 行 3 列的数据集。 The columns are country, latitude and longitude.列是国家/地区、纬度和经度。 I am trying to plot all the 34 points on that map.我试图在该地图上绘制所有 34 个点。

Code:代码:

library(RODBC)
library(googleVis)
con <- odbcConnect("Data", uid = "username", pwd = "password")
Geo <- sqlQuery(con, "select * from ANA.R.vwGeo")

m <- leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addCircles(lng=Geo$lon, lat=Geo$lat, popup=Geo$country)
m # Print the map

This code prints the circles on the map but only 8 of them.此代码在地图上打印圆圈,但只有 8 个。 After checking i realized that it only plotted the top 8 rows and ignored the rest?检查后我意识到它只绘制了前 8 行而忽略了其余的行? Not sure how to change this.不知道如何改变这一点。

structure(list(country = c("Argentina", "Australia", "Austria", 
"Belgium", "Brazil", "Canada", "China", "Denmark", "Europe", 
"France", "Germany", "India", "Ireland", "Israel", "Italy", "Japan", 
"Korea, Republic of", "Norway", "Philippines", "Poland", "Portugal"
), lat = c(-36.536119, -24.211317, 47.751901, 50.755453, -11.066766, 
60.739101, 35.716703, 55.946866, NA, 46.97068, 51.295789, 22.518114, 
53.297545, 31.191818, 43.259406, 36.110262, 36.641155, 62.153742, 
15.137269, 52.22507, 39.77707), Ion = c(-64.653608, 134.654116, 
14.559724, 4.646748, -50.060384, -101.625, 103.696658, 9.554184, 
NA, 2.846033, 10.563983, 78.560473, -7.812353, 34.881909, 12.419802, 
138.462604, 128.085175, 9.363357, 121.232504, 19.452793, -7.908592
)), .Names = c("country", "lat", "Ion"), class = "data.frame", row.names = c(NA, 
-21L)) -> Geo

Looking at your plot, the issue is likely caused by NA values for row 9 "Europe".看看你的情节,这个问题很可能是由第 9 行“欧洲”的NA值引起的。 Not sure why plotting stops, but you can at least try with NA lines removed with:不知道为什么绘图停止,但您至少可以尝试删除NA行:

Geo <- Geo[!is.na(Geo$lon) & !is.na(Geo$lat), ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM