Mapping a categorical variable with googleVis

122 views Asked by At

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. I will eventually be using this map in a Shiny app. Any help is much appreciated.

P.S. I honestly don't care that much about using googleVis for this. If there's another package that will allow me to map a categorical variable and have tool tips appear on mouseover, I'm open to switching.

0

There are 0 answers