我试图弄清楚如何在highcharter
-tooltip_chart
中包括其他信息。我想创建一个散点图,并创建另一个散点图作为tooltip_chart
,其中点的大小和/或颜色基于变量。
我想将这种类型的情节作为我的tooltip_chart
library(highcharter)
library(tidyverse)
library(gapminder)
data(gapminder, package = "gapminder")
hchart(gapminder %>% filter(country == "Afghanistan"), "scatter", hcaes(x= year, y = pop, group = country, size = gdpPercap))
在此主图表中
gp <- gapminder %>%
filter(country %in% c("Afghanistan", "Belgium", "India", "Lesotho")) %>%
arrange(desc(year)) %>%
distinct(country, .keep_all = TRUE)
gp2 <- gapminder %>%
filter(country %in% c("Afghanistan", "Belgium", "India", "Lesotho")) %>%
select(country, year, pop, gdpPercap) %>%
nest(-country) %>%
mutate(
data = map(data, mutate_mapping, hcaes(x = year, y = pop), drop = TRUE),
data = map(data, list_parse)
) %>%
rename(ttdata = data)
gptot <- left_join(gp, gp2, by = "country")
hchart(gptot, "scatter", hcaes(x = lifeExp, y = gdpPercap, name = country, size = pop, group = continent)) %>% hc_yAxis(type = "logarithmic")
像这样:
hchart(
gptot,
"point",
hcaes(lifeExp, gdpPercap, name = country, size = pop, group = continent)
) %>%
hc_yAxis(type = "logarithmic") %>%
# here is the magic (inside the function)
hc_tooltip(useHTML = TRUE, pointFormatter = tooltip_chart(accesor = "ttdata",
hc_opts = list(chart = list(type = "scatter"))))
我尝试了以下操作但未成功
data = map(data, mutate_mapping, hcaes(x = year, y = pop, color = gdpPercap), drop = TRUE)
data = map(data, mutate_mapping, hcaes(x = year, y = pop, size = gdpPercap), drop = TRUE)
hc_opts = list(series = list(list(color = "point.col")))