tooltip_chart中的其他信息

时间:2019-04-25 09:43:47

标签: r r-highcharter

我试图弄清楚如何在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))

enter image description here

在此主图表中

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")

enter image description here

像这样:

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"))))

enter image description here

我尝试了以下操作但未成功

  1. data = map(data, mutate_mapping, hcaes(x = year, y = pop, color = gdpPercap), drop = TRUE)
  2. data = map(data, mutate_mapping, hcaes(x = year, y = pop, size = gdpPercap), drop = TRUE)
  3. 在为数据添加颜色后修改hc_opts = list(series = list(list(color = "point.col")))

0 个答案:

没有答案