如何在 r 的 highcharter 中为树图添加数据标签?

How to add data labels for a treemap in highcharter in r?

我想为我创建的树状图添加数据标签。我将此树状图用于图像,因此为每个框设置 ptsfgpct 会有所帮助。我希望工具提示中列出的内容和图例显示在每个框中。

我的代码:

library(highcharter)

gamelogs %>%
  filter(slugTeam == "MEM") %>%
  group_by(namePlayer) %>%
  summarise(pts = sum(pts), fgpct = sum(fgm) / sum(fga)) %>%
  hchart("treemap", hcaes(name = namePlayer, value = pts, color = fgpct)) %>%
  hc_title(text = "Grizzlies Scoring") %>%
  hc_subtitle(text = "Shaded by Field Goal %") %>%
  hc_chart(
    backgroundColor = '#FFFFFF' # Chart Background Color
  ) %>%
  hc_exporting(enabled = TRUE,
               filename = "Grizzlies Scoring")

我的输出:

我想要的输出:

此输出将在框中包含点 1,041 以及图例中显示的 49% 的 fgpct。无论如何要使用 highcharter treemap 添加数据标签?

试试这个

gamelogs %>%
  filter(slugTeam == "MEM") %>%
  group_by(namePlayer) %>%
  summarise(pts = sum(pts), fgpct = round(sum(fgm) / sum(fga),digits=2)) %>% 
  hchart("treemap", hcaes(name = namePlayer, value = pts, color = fgpct),
         dataLabels = list(enabled = TRUE, format='{point.namePlayer}<br/>{point.pts} pts<br/>{point.fgpct} fgpct'),
         tooltip = list(pointFormat = "{point.namePlayer}: {point.pts}, {point.fgpct}%")) %>%
  hc_title(text = "Grizzlies Scoring") %>%
  hc_subtitle(text = "Shaded by Field Goal %") %>%
  hc_chart(
    backgroundColor = '#FFFFFF' # Chart Background Color
  ) %>%
  hc_exporting(enabled = TRUE,
               filename = "Grizzlies Scoring") %>% 
  hc_tooltip(crosshairs = TRUE)

你会得到这个输出