How to map categorical variables in gvisGeoMap/gvisGeoChart

99 views
Skip to first unread message

David Zornek

unread,
Aug 25, 2015, 5:42:32 PM8/25/15
to Google Visualization API

I am attempting to create a map in which each US state is colored according to a character type categorical variable. I am able to get the map to render, but all of the tooltips show a numeric value instead of the character string in my variable. Here's a reproducible example:

library(googleVis)
library(datasets)


category <- c("A","B","C","D","E",
           "A","B","C","D","E",
           "A","B","C","D","E",
           "A","B","C","D","E",
           "A","B","C","D","E",
           "A","B","C","D","E",
           "A","B","C","D","E",
           "A","B","C","D","E",
           "A","B","C","D","E",
           "A","B","C","D","E")

hover <- c(1:50)

data <- data.frame(state.name,category,hover)

Map <- gvisGeoMap(data, "state.name", "category", "hover",
                    options=list(region="US", 
                                 displayMode="regions", 
                                 resolution="provinces",
                                 width=600, height=400))
plot(Map)

The map assigns colors correctly for "category," but the tooltip shows category as a number, rather than a letter A - E. Ultimately, I would like to be able to assign discrete colors to each category, rather than using a gradient, but I'll take one step at a time with my questions. The end goal is to use this map in a Shiny app. Any help is much appreciated.


P.S. I've tried gvisGeoChart with essentially the same result. Simply assigning hover = category doesn't work in my situation; in the final product, I will be displaying a separate hover variable in the tool tip.

Sergey Grabkovsky

unread,
Aug 26, 2015, 9:44:53 AM8/26/15
to Google Visualization API
Hi David,

I'm not really sure what gvisGeoMap does, since it's not officially supported by Google, but here's an example of how you can do it in JavaScript: http://jsfiddle.net/LLknt4cc/1/

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/7b21882e-f786-41c5-9da4-f1293ea175b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Zornek

unread,
Aug 26, 2015, 11:32:20 PM8/26/15
to Google Visualization API
Thanks a bunch. I think I can make that work!
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages