Changing point color on a gvisMap in the googleVis R package

1.4k views Asked by At

I am using the googleVis package in R, and specifically I am trying to work something out with the gvisMap command. As an example, I will use the Hurriance Andrew data shown here:

AndrewMap <- gvisMap(Andrew, "LatLong" , "Tip", 
                     options=list(showTip=TRUE, 
                                  showLine=TRUE, 
                                  enableScrollWheel=TRUE,
                                  mapType='terrain', 
                                  useMapTypeControl=TRUE))
plot(AndrewMap)

I would like to change the color of the points. For example, using gvisGeoMap or gvisGeoChart I can make the points different colours based upon some variable, but the problem is you loose the zooming, centring and scrolling that you get with gvisMap. Also I have categorical, not continuous data, so I want to color the points, using gvisMap, based upon some categorical variable attributed to that point.

I have tried messing around with options, but these are just configuration options, and it appears that gvisMap itself doesn't have default option to change the point color. Any suggestions for alternative ways this could be done?

1

There are 1 answers

0
PereG On

Try plotGoogleMaps package. That's works for me.

library(plotGoogleMaps); library(sp)
library(googleVis) # for the data
data(Andrew)
coordinates(Andrew) = ~ Long + Lat      
proj4string(Andrew) = CRS("+proj=longlat +datum=WGS84")
Andrew2 <- SpatialPointsDataFrame(Andrew, data = data.frame( ID = row.names(Andrew) ) )  
m <- plotGoogleMaps(Andrew2, filename='myMap1.html')

Also, this works for categorical variables.

ic <- iconlabels(attribute = Andrew$Category, colPalette=rainbow(3), icon=TRUE, at=NULL, height=10, scale=0.6)
m <- plotGoogleMaps(Andrew2, filename='myMap1.html', iconMarker=ic)

I found a greater variety of controls in the plotGoogleMaps package, and although the treatment of the coordinates is more difficult for non-experts, is accessible.