Дополнительная информация в tooltip_chart - PullRequest
0 голосов
/ 25 апреля 2019

Я пытаюсь выяснить, как включить дополнительную информацию в 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

Iбезуспешно пробовал следующее

  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"))) после добавления цветов в мои данные
...