我无法使用 Highcharter 在 R 中重新创建此答案,以将条形图中的条形变为可点击的 URL。这是答案中的Javascript代码。Highcharter 有一个关于我试图遵循的重新创建 Javascript的小插曲。这是迄今为止尝试过的。它没有显示任何条形图。
library(tidyverse)
library(highcharter)
highchart() %>%
hc_chart(type = "column") %>%
hc_title(text = "Click points to go to URL") %>%
hc_xAxis(type = "category") %>%
hc_plotOptions(series = list(cursor = "pointer"),
point =
list(events = list(
click = JS(
"function () {
location.href = 'https://en.wikipedia.org/wiki/' +
this.options.key;
}"
)
))) %>%
hc_series(
list(name = "USA", key = "United_States", y = 29.9),
list(name = "Canada", key = "Canada", y = 71.5),
list(name = "Mexico", key = "Mexico", y = 106.4)
)