希望在 highcharter 中復制以下 ggplot 邏輯。
ggplot(iris, aes(Sepal.Length, Petal.Length, color = Species))
geom_point()
scale_color_manual(values = c("red", "green", "blue"), labels = c("My custom species name", "Another species name", "Species XYZ"))
這是我能做的最接近的
highchart() |>
hc_add_series(data = iris, type = "scatter", hcaes(x = Sepal.Length, y = Petal.Length, group = Species)) |>
hc_colors(colors = c("red", "green", "blue"))
問題是我需要手動覆寫組名而不更改基礎資料。我知道可以使用 單獨添加每個組hc_add_series(),但這不是一個優雅的解決方案,尤其是當組的數量很大時。想知道是否有類似于 ggplot 中可用的代碼邏輯。
uj5u.com熱心網友回復:
找到了簡單但不直觀的解決方案。顯然,name引數 inhc_add_series()可以采用名稱向量。如果names改為命名這個論點,可能會更直觀。
highchart() |>
hc_add_series(data = iris, type = "scatter", hcaes(x = Sepal.Length, y = Petal.Length, group = Species),
name = c("My custom species name", "Another species name", "Species XYZ")) |>
hc_colors(colors = c("red", "green", "blue"))
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/451746.html
標籤:r ggplot2 高图表 r-highcharter
