[英]How to add data labels for a treemap in highcharter in r?
I want to add data labels for a treemap I have created.我想为我创建的树形图添加数据标签。 I am using this treemap for an image so having the pts
and fgpct
for each box would be helpful.我将此树形图用于图像,因此为每个框设置pts
和fgpct
会很有帮助。 I want what's listed in the tooltip and the legend to appear in each box.我希望工具提示中列出的内容和图例出现在每个框中。
My code:我的代码:
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")
The output I would like: output 我想:
This output would have the points 1,041 in the box and also the fgpct of 49% that is shown in the legend.此 output 将在框中具有点 1,041,并且图例中显示的 fgpct 为 49%。 Anyway to add the data labels using highcharter treemap?无论如何要使用 highcharter 树形图添加数据标签?
Try this尝试这个
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)
you will get this output你会得到这个 output
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.