I'm having issues running some code to plot markers on a US map using googleVis
and gvisGeoChart()
. I can run the following example, no problems:
require(datasets)
library(googleVis)
GeoMarker <- gvisGeoChart(Andrew, "LatLong",
sizevar='Speed_kt',
colorvar="Pressure_mb",
options=list(region="US"))
plot(GeoMarker)
Here is the kind of code I'm using. I'm attempting to bring lists of values into a data frame and then use this data to plot markers on a US map.
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)
I then receive the following error:
Error in data.frame(Latitude = numeric(0), Longitude = numeric(0), Rank = c(2, : arguments imply differing number of rows: 0, 3
I have searched and can't find too many tutorials on using googleVis
in R and especially with regards to gvisGeoChart apart from the documentation. I've inspected the Andrew
data frame and used str()
and can't find anything different between the two data sets.
Thanks for any and all help and please let me know if you need any clarification!
This work for me:
new$latlong<-paste(new$lat, new$lon, sep=":")
TestPlot <- gvisGeoChart(new, "latlong", colorvar='Rank',options=list(displayMode="Markers", region="US"))
plot(TestPlot)
I think it's just the way your lat/lon were formatted.