我每次搜索关键字时都会尝试使用googleVis生成Intensity地图。我有三个与googleVis有关的问题:
这是代码:
process_google_data <- function(keyword) {
if (trimws(keyword) != "") {
#retrieves raw data from google trends
gtrends_data <-
gtrends(trimws(keyword), cat = "0", session = session)
#generates intensity map data for plotting
top_regions <-
gtrends_data[5] %>% ldply(., data.frame) %>% .[, 2:3]
top_regions$Region %<>% toupper
top_regions %<>% join(y = countries_data,
type = "inner",
match = "first") %>% .[order(.[2]), c(1, 3, 2)]
intensity_data <-
data.frame(country = top_regions[, 2] %>% as.vector,
Intensity = top_regions[, 3],
empty = rep(NA, NROW(top_regions))) %>% gvisIntensityMap #for some reasons, two tabs are necessary to display the plot
gtrends_data$trend$start %<>% sub("^(.{8})(?:\\d{2})", "\\101", .)
gtrends_data <-
tapply(gtrends_data$trend$hits,
gtrends_data$trend$start,
mean) %>% cbind(names(.), .) %>% as.data.frame
colnames(gtrends_data) <- c("Date", "hits")
row.names(gtrends_data) <- 1:NROW(gtrends_data)
gtrends_data[, 2] %<>% as.integer
return(list(gtrends_data, intensity_data))
}}
shinyServer(function(input, output, session) {
observeEvent(input$search,
{
# browser()
go <- process_google_data(input$keyword)
output$intensityPlot <- htmlOutput({ plot(go[[2]], tag ='chart') })
go
})
})
如果你能提供帮助,那就太有意义了。感谢。