在 highcharter 散点图上标记点
Labelling Points on a highcharter scatter chart
我想在高散点图中标记每个单独的点。下面的代码生成一张图表:
library(highcharter)
df = data.frame(name = c("tom", "dick", "harry"),
height = c(170L,180L, 185L),
weight = c(65L, 68L, 75L))
highchart() %>%
hc_add_series(df, type = "scatter", hcaes(x = weight, y = height), showInLegend = FALSE) %>%
hc_tooltip(pointFormat = "height: {point.y} <br> weight: {point.x}")
将鼠标悬停在每个点上显示:"series 1, height: 170, weight: 65" 等。
我希望标签在鼠标悬停在汤姆上方时显示 "tom, height: 170, weight: 65",对于迪克和哈利也是如此。
谢谢
我刚刚在 hcaes
中添加了组变量
highchart() %>%
hc_add_series(df,type = "scatter",
hcaes(x = weight, y = height, group=name), showInLegend = FALSE) %>%
hc_tooltip(pointFormat = "height: {point.y} <br> weight: {point.x}")
而且效果很好。
根据评论,我提出了另一种选择。
选项 1
将highchart()
更改为hchart()
hchart(df,type = "scatter",
hcaes(x = weight, y = height, group = name),
showInLegend = FALSE) %>%
hc_tooltip(pointFormat = "height: {point.y} <br> weight: {point.x}")
选项 2
使用 hc_add_series
中的 marker
选项。
highchart() %>%
hc_add_series(df,type = "scatter",
hcaes(x = weight, y = height, group = name),
showInLegend = FALSE,
marker = list(symbol = fa_icon("circle")),
color = "blue") %>%
hc_tooltip(pointFormat = "height: {point.y} <br> weight: {point.x}")
我想在高散点图中标记每个单独的点。下面的代码生成一张图表:
library(highcharter)
df = data.frame(name = c("tom", "dick", "harry"),
height = c(170L,180L, 185L),
weight = c(65L, 68L, 75L))
highchart() %>%
hc_add_series(df, type = "scatter", hcaes(x = weight, y = height), showInLegend = FALSE) %>%
hc_tooltip(pointFormat = "height: {point.y} <br> weight: {point.x}")
将鼠标悬停在每个点上显示:"series 1, height: 170, weight: 65" 等。 我希望标签在鼠标悬停在汤姆上方时显示 "tom, height: 170, weight: 65",对于迪克和哈利也是如此。
谢谢
我刚刚在 hcaes
highchart() %>%
hc_add_series(df,type = "scatter",
hcaes(x = weight, y = height, group=name), showInLegend = FALSE) %>%
hc_tooltip(pointFormat = "height: {point.y} <br> weight: {point.x}")
而且效果很好。
根据评论,我提出了另一种选择。
选项 1
将highchart()
更改为hchart()
hchart(df,type = "scatter",
hcaes(x = weight, y = height, group = name),
showInLegend = FALSE) %>%
hc_tooltip(pointFormat = "height: {point.y} <br> weight: {point.x}")
选项 2
使用 hc_add_series
中的 marker
选项。
highchart() %>%
hc_add_series(df,type = "scatter",
hcaes(x = weight, y = height, group = name),
showInLegend = FALSE,
marker = list(symbol = fa_icon("circle")),
color = "blue") %>%
hc_tooltip(pointFormat = "height: {point.y} <br> weight: {point.x}")