我正在 R 中使用 Highcharter 制作气泡图表。但是我无法修改气泡大小图例的颜色或图例中显示的气泡大小的范围,即我无法翻译将 Javascript 语法 here 转换为 R。例如,在下面的说明图中,将气泡图例的蓝色更改为黑色,并将显示大小从 214、7506.5 和 14799 更改为 1000、7000 和 14000。
mydata <- tibble(x=sample(seq(1,30,1), 30, replace=T),
y=sample(seq(1,150,1), 30, replace=T),
group=sample(seq(1,3,1), 30, replace=T),
size=sample(seq(1,15000,1), 30, replace=T))
hchart(mydata, type = "bubble",
hcaes(x = x, y = y, size = size, color = group), maxSize = "10%",
showInLegend = F) %>%
hc_legend(bubbleLegend = list(enabled = T))
我非常感谢您的帮助。
您可以在下面找到这个 R 演示的示例: https://jsfiddle.net/BlackLabel/x5kLracd/
如您所见,图例在那里正常工作。 我希望这个配置能让你的工作更轻松!
library(highcharter)
highchart() %>%
hc_chart(type = "bubble") %>%
hc_legend(
enabled = TRUE,
align = 'left',
layout = 'vertical',
verticalAlign = 'top',
itemMarginTop = 10,
bubbleLegend = list(
enabled = TRUE,
borderWidth = 1,
connectorDistance = 40,
maxSize = 70,
ranges = list(list(), list(), list(color = '#e4d354'))
)
) %>%
hc_plotOptions(
series = list(
maxSize = 70
)
) %>%
hc_add_series(
data = list(
list(x = 95, y = 95, z = 834),
list(x = 86.5, y = 102.9, z = 1000),
list(x = 80.8, y = 91.5, z = 242),
list(x = 80.4, y = 102.5, z = 121)
)
) %>%
hc_add_series(
data = list(
list(x = 80.3, y = 86.1, z = 358),
list(x = 78.4, y = 70.1, z = 450),
list(x = 74.2, y = 68.5, z = 598)
)
) %>%
hc_add_series(
data = list(
list(x = 73.5, y = 83.1, z = 678),
list(x = 71, y = 93.2, z = 314),
list(x = 69.2, y = 57.6, z = 415),
list(x = 68.6, y = 20, z = 799)
)
) %>%
hc_add_series(
data = list(
list(x = 65.5, y = 126.4, z = 35.3),
list(x = 65.4, y = 50.8, z = 28.5),
list(x = 63.4, y = 51.8, z = 15.4),
list(x = 64, y = 82.9, z = 31.3)
)
)