[英]How to create a tooltip chart in r using highcharter?
我正在使用highcharter
库并参考下面的链接在气泡图中创建交互式工具提示图表
https://jkunst.com/blog/posts/2019-02-04-using-tooltips-in-unexpected-ways/
Plot 图像:
使用链接中显示的gapminder
数据,我能够重现相同的数据,但是当我使用其他数据时,工具提示图表不会出现。
我的其他数据的代码:
库
library(tidyverse)
library(highcharter)
数据
grouped_cases_df <- read.csv("https://raw.githubusercontent.com/johnsnow09/covid19-df_stack-code/main/grouped_cases.csv")
tt_base <- grouped_cases_df %>%
arrange(desc(Date)) %>%
distinct(Country.Region, .keep_all = TRUE)
tt_base
tt_inner <- grouped_cases_df %>%
select(Country.Region, Date, Daily_cases) %>%
nest(-Country.Region) %>%
mutate(
data = map(data, mutate_mapping, hcaes(x = Date, y = Daily_cases), drop = TRUE),
data = map(data, list_parse)
) %>%
rename(tt_nestdata = data)
tt_inner
tt_daily <- left_join(tt_base, tt_inner, by = "Country.Region")
tt_daily
hchart(
tt_daily,
"point",
hcaes(x = Active, y = Confirmed, name = Country.Region,
size = Daily_cases, group = continent, name = Country.Region)
) %>%
hc_yAxis(type = "logarithmic") %>%
hc_tooltip(
useHTML = TRUE,
headerFormat = "<b>{point.key}</b>",
pointFormatter = tooltip_chart(accesor = "tt_nestdata")
) %>%
hc_title(text = "Active Vs Confirmed Cases as of latest Date") %>%
hc_subtitle(text = "Size of bubble based on Deaths <br> (ttchart: population growth)")
问题:获取每个国家/地区的空白工具提示图表。
我还尝试将Country.Region
更改为as.factor()
但没有帮助。 我不确定这有什么问题。
需要进行两个更改:
mutate(Date = highcharter::datetime_to_timestamp(lubridate::ymd(Date)))
tooltip_chart
function 中的hc_opts
参数中,您需要指定 x 轴将值视为日期。pointFormatter = tooltip_chart(accesor = "tt_nestdata", hc_opts = list(xAxis = list(type = "datetime")))
然后:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.