使用googleVis映射分类变量

时间:2015-08-25 20:32:28

标签: r shiny googlevis gvisgeomap

我正在尝试创建一个地图,其中每个美国州根据字符类型分类变量着色。我能够渲染地图,但所有工具提示都显示数值而不是变量中的字符串。这是一个可重复的例子:

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)

地图为“类别”正确分配颜色,但工具提示将类别显示为数字,而不是字母A - E.最后,我希望能够为每个类别指定离散颜色,而不是使用渐变,但我会一步一步地提出问题。我最终将在一个闪亮的应用程序中使用这个地图。非常感谢任何帮助。

P.S。老实说,我并不关心使用googleVis。如果有另一个包允许我映射一个分类变量并在鼠标悬停时显示工具提示,我可以切换。

0 个答案:

没有答案