gvisGeoChart无法识别标记的Lat / Long

时间:2016-03-16 18:49:03

标签: r googlevis

我在运行一些代码时遇到问题,使用googleVisgvisGeoChart()在美国地图上绘制标记。我可以运行以下示例,没有问题:

require(datasets)
library(googleVis)

GeoMarker <- gvisGeoChart(Andrew, "LatLong", 
                          sizevar='Speed_kt',
                          colorvar="Pressure_mb", 
                          options=list(region="US"))
plot(GeoMarker)

这是我正在使用的代码。我正在尝试将值列表放入数据框中,然后使用此数据在美国地图上绘制标记。

library(googleVis)
library(ggmap)

cities <- c("Norman, OK", "Madison, WI", "Tallahassee, FL")
test <- as.data.frame(cities)
test$rank <- c(2,1,3)
colnames(test) <- c("City","Rank")
geocodes <- geocode(as.character(test$City))
new <- data.frame(test[,1:2],geocodes)

TestPlot <- gvisGeoChart(new, sizevar='Rank',options=list(region="US"))
plot(TestPlot)

然后我收到以下错误:

Error in data.frame(Latitude = numeric(0), Longitude = numeric(0), Rank = c(2, : arguments imply differing number of rows: 0, 3

我已经搜索过,在R中找不到太多关于使用googleVis的教程,特别是关于gvisGeoChart的文档。我检查了Andrew数据框并使用了str(),但在两个数据集之间找不到任何不同之处。

感谢您提供的任何帮助,如果您需要任何澄清,请与我们联系!

1 个答案:

答案 0 :(得分:1)

这项工作对我来说:

new$latlong<-paste(new$lat, new$lon, sep=":")
TestPlot <- gvisGeoChart(new, "latlong", colorvar='Rank',options=list(displayMode="Markers", region="US"))
plot(TestPlot)

我认为这只是你的lat / lon格式化的方式。

相关问题