我正在尝试创建一个地图,其中每个美国州都根据字符类型分类变量进行着色。我能够让地图呈现,但所有工具提示都显示一个数值而不是我的变量中的字符串。这是一个可重现的示例:
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。最终,我希望能够为每个类别分配离散颜色,而不是使用渐变,但是我会一步一步回答我的问题。我最终会在 Shiny 应用程序中使用这张地图。任何帮助深表感谢。
PS 老实说,我不太关心为此使用 googleVis。如果有另一个包允许我映射分类变量并在鼠标悬停时显示工具提示,我愿意切换。