0

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.

  • 1
    One way could be `hovervar = "category"`. That is, `gvisGeoMap(data = data, locationvar = "state.name", numvar = "category", hovervar = "category", options = ...` In this way, you can certainly show the characters you want. But you still see the numbers at the same time. This is, I think, because `numvar` is using numbers assigned to a factor. If you make `category` character, you would see the reason why you cannot really have character for `numvar` in `gvisGeoMap`. That's all I can say for now. – jazzurro Aug 26 '15 at 01:36
  • Yes, I had considered that, and it doesn't work for my situation for a couple of reasons. You point out one of them---that numbers are still shown---which will be confusing for my users. Another is that I ultimately need to give users the ability to select the statistic passed to hovervar. One of the Google engineers offered me a javascript solution that I think will work, which I'll share here in a separate comment. Thanks for your reply! – David Zornek Aug 27 '15 at 17:47
  • 1
    A javascript solution offered by one of Google's engineers can be viewed on JSFiddle: http://jsfiddle.net/LLknt4cc/1/ – David Zornek Aug 27 '15 at 17:48
  • Thanks for the link. When I want to do something similar, I will use the code.:) – jazzurro Aug 27 '15 at 23:24

0 Answers0