我正在嘗試將工具提示分層到美國地圖,但無論我在哪裏懸停......它都顯示相同的數據。另外,數據是錯誤的。我在想它是通過了因素值而不是字符值。我試着從電影資源管理器的示例 - http://shiny.rstudio.com/gallery/movie-explorer.html中獲取技巧 - 但是,它並不像我所希望的那樣工作。任何提示或線索,我應該看看?ggvis地圖和工具提示
更新:我確定你只能通過調用ggvis
函數的參數。所以,如果我的工具提示功能包括region
,long
,& lat
,它們都會出現在工具提示中。由於Population
和Income
不會出現在函數的任何位置,因此不會傳遞它們。我仍然不知道如何繼續,但任何想法都會很棒! :)
library(ggplot2)
library(shiny)
library(ggvis)
library(dplyr)
shinyApp(
ui = fluidPage(
#numericInput("n", "n", 1),
ggvisOutput("map")
),
server = function(input, output) {
statesData <- reactive({
states <- data.frame(state.x77)
states$region <- row.names(state.x77) %>% tolower
row.names(states) <- NULL
all_states <- map_data("state") %>%
mutate(region = tolower(region)) %>%
left_join(states)
all_states_unique <- all_states %>%
select(region, Population, Income, Illiteracy, Life.Exp, Murder, HS.Grad, Frost, Area) %>%
unique
states_tooltip <- function(x) {
if (is.null(x)) return(NULL)
if (is.null(x$region)) return(NULL)
# Pick out the movie with this ID
allStates <- isolate(all_states_unique)
state <- allStates[allStates$region == x$region, ]
paste0("<b>", state$region, "</b><br>",
state$Population, "<br>",
state$Income
)
}
all_states %>%
arrange(group, order) %>%
ggvis(x = ~long, y = ~lat) %>%
layer_paths(fill = ~region, stroke := .2) %>%
add_tooltip(states_tooltip, "hover")
})
statesData %>% bind_shiny('map')
}
)
可能與[這個問題](http://stackoverflow.com/questions/24493278/ggvis-density-plot-with-tooltip/24498139# 24498139) – Jaap 2014-11-14 17:42:15