是否有最多的点可以用gvisMap绘制?或者gvisMap不会绘制所有的点

时间:2022-11-20 22:49:05

EDIT After three days of little interest, I am adding a fully reproducible example... The code below makes 1400 locations. The first 700 points are centered around the first area, the 2nd 700 points are centered around a 2nd area to the northwest.

经过三天的编辑,我添加了一个完全可复制的示例……下面的代码创建了1400个位置。第一个700点集中在第一个区域,第二个700点集中在西北的第二个区域。

datOne <- data.frame(
  Long = runif(700, -111.180000, -110.950000 ),
  Lat = runif(700, 43.180000, 43.440000),
  Area = "First")

datTwo <- data.frame(
  Long = runif(700, -111.850000, -110.900000),
  Lat = runif(700, 43.910000, 44.000000),
  Area = "Second")

dat <- rbind(datOne, datTwo)
dat$LatLong <- paste(dat$Lat, dat$Long, sep = ":")

head(dat)
       Long      Lat  Area                            LatLong
1 -110.9701 43.19509 First 43.1950901590148:-110.970063584852
2 -111.0258 43.25338 First 43.2533758980362:-111.025837010061
3 -111.1737 43.18016 First  43.180157370572:-111.173737878765
4 -111.1130 43.41193 First 43.4119294773275:-111.112970910808
5 -110.9909 43.34044 First 43.3404393909033:-110.990947539737
6 -110.9800 43.33428 First 43.3342766285082:-110.979969937215

If I try to plot the points with gvisMap then only the locations centered around the first area apear in the map as is reproduced with the following code

如果我尝试用gvisMap绘制这些点,那么只有在地图上的第一个区域的位置以下面的代码复制。

library(googleVis)
M2 <- gvisMap(dat, "LatLong", 
              options=list(showLine=TRUE, enableScrollWheel=TRUE, 
                           mapType='satlite', useMapTypeControl=TRUE, 
                           width="800", height="800",
                           colors = "['#0000ff']",
                           icons=paste0("{","'default': {'normal':
                                        'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png',\n",
                                        "'selected':'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png'",
                                        "}}")
              ))
plot(M2)

To confirm that all the locations are formatted correctly I can subset the dataframe to plot points 500:1000 which includes locations in both areas. Changing the first line of code to

为了确认所有的位置都被正确地格式化,我可以将dataframe子集划分为plot points 500:1000,其中包括两个区域的位置。将第一行代码更改为

M2 <- gvisMap(dat[500:1000, ], "LatLong", 

will correctly display locations in both areas. So, the issue does not seem to be formatting, but maybe there is a maximum number of points that can be plotted..?

将正确显示两个区域的位置。所以,这个问题似乎不是格式化的问题,但是可能有一个最大的点可以被绘制出来。?

Is it possible to plot all locations in the reproducible data included herein?

是否有可能绘制出包含在此的可再现数据中的所有位置?

Any suggestions or code to plot all of the points in the datdataframe above would be greatly appreciated. I am happy to take suggested code from other packages such as leaflet mentioned in the comments.

如果您有任何建议或代码来绘制上面datdataframe中的所有点,我们将非常感激。我很高兴从其他包中获取建议代码,比如在评论中提到的传单。

3 个解决方案

#1


1  

Check out the example below. This uses the R leaflet package and binds a popup to the markers from the area column.

看看下面的例子。这将使用R单张包并将弹出窗口绑定到区域列的标记。

library(leaflet)

datOne <- data.frame(
  lng = runif(700, -111.180000, -110.950000 ),
  lat = runif(700, 43.180000, 43.440000),
  Area = "First")

datTwo <- data.frame(
  lng = runif(700, -111.850000, -110.900000),
  lat = runif(700, 43.910000, 44.000000),
  Area = "Second")

dat <- rbind(datOne, datTwo)
dat$latLng <- paste(dat$lat, dat$lng, sep = ":")

map<-leaflet(dat)
map<-addTiles(map)
map<-addMarkers(map,~lng,~lat,popup = ~as.character(Area))
map

#2


1  

Yes, there is a maximum number of points that can be displayed using Google Maps API, through googleVis

是的,通过googleVis,可以使用谷歌地图API显示最多的点。

As noted here: [https://developers.google.com/chart/interactive/docs/gallery/map#data-format]

注意:[https://developers.google.com/chart/interactive/docs/gallery/map数据格式)

Note: The Lat-Long pairs option loads maps much faster, especially with large data. We recommend that you use this option for large data sets. Please visit Google Maps API to find out how to transform your addresses to lat-long points. The map can display a maximum of 400 entries; if your data holds more than 400 rows, only the first 400 will be shown.

注意:latlong对选项的加载速度更快,特别是大数据。我们建议您对大型数据集使用此选项。请访问谷歌地图API,了解如何将您的地址转换为长时间点。该地图最多可显示400个条目;如果您的数据保存超过400行,只显示第一个400行。

The above leaflet works great for data sets larger than 400 points.

以上资料单张适用于超过400分的资料集。

#3


1  

Just to throw this into the mix here, as the question is about maximum number of points. In case you ever find yourselves in the need of plotting points (or polygons or lines) in the order of tens of thousands or millions, mapview would be an option:

我把这个加入到这里,因为问题是关于最大点数的。如果您发现您需要绘制点(或多边形或线),以数以万计或数百万计,mapview将是一个选项:

library(mapview)
library(sp)

datOne <- data.frame(
  lng = runif(70000, -111.180000, -110.950000 ),
  lat = runif(70000, 43.180000, 43.440000),
  Area = "First")

coordinates(datOne) <- ~ lng + lat
proj4string(datOne) <- "+init=epsg:4326"

mapview(datOne)

Note that mapview only works with spatial classes, therefore needs a valid proj4string()

注意,mapview只适用于空间类,因此需要一个有效的proj4string()

#1


1  

Check out the example below. This uses the R leaflet package and binds a popup to the markers from the area column.

看看下面的例子。这将使用R单张包并将弹出窗口绑定到区域列的标记。

library(leaflet)

datOne <- data.frame(
  lng = runif(700, -111.180000, -110.950000 ),
  lat = runif(700, 43.180000, 43.440000),
  Area = "First")

datTwo <- data.frame(
  lng = runif(700, -111.850000, -110.900000),
  lat = runif(700, 43.910000, 44.000000),
  Area = "Second")

dat <- rbind(datOne, datTwo)
dat$latLng <- paste(dat$lat, dat$lng, sep = ":")

map<-leaflet(dat)
map<-addTiles(map)
map<-addMarkers(map,~lng,~lat,popup = ~as.character(Area))
map

#2


1  

Yes, there is a maximum number of points that can be displayed using Google Maps API, through googleVis

是的,通过googleVis,可以使用谷歌地图API显示最多的点。

As noted here: [https://developers.google.com/chart/interactive/docs/gallery/map#data-format]

注意:[https://developers.google.com/chart/interactive/docs/gallery/map数据格式)

Note: The Lat-Long pairs option loads maps much faster, especially with large data. We recommend that you use this option for large data sets. Please visit Google Maps API to find out how to transform your addresses to lat-long points. The map can display a maximum of 400 entries; if your data holds more than 400 rows, only the first 400 will be shown.

注意:latlong对选项的加载速度更快,特别是大数据。我们建议您对大型数据集使用此选项。请访问谷歌地图API,了解如何将您的地址转换为长时间点。该地图最多可显示400个条目;如果您的数据保存超过400行,只显示第一个400行。

The above leaflet works great for data sets larger than 400 points.

以上资料单张适用于超过400分的资料集。

#3


1  

Just to throw this into the mix here, as the question is about maximum number of points. In case you ever find yourselves in the need of plotting points (or polygons or lines) in the order of tens of thousands or millions, mapview would be an option:

我把这个加入到这里,因为问题是关于最大点数的。如果您发现您需要绘制点(或多边形或线),以数以万计或数百万计,mapview将是一个选项:

library(mapview)
library(sp)

datOne <- data.frame(
  lng = runif(70000, -111.180000, -110.950000 ),
  lat = runif(70000, 43.180000, 43.440000),
  Area = "First")

coordinates(datOne) <- ~ lng + lat
proj4string(datOne) <- "+init=epsg:4326"

mapview(datOne)

Note that mapview only works with spatial classes, therefore needs a valid proj4string()

注意,mapview只适用于空间类,因此需要一个有效的proj4string()