R highcharter图点颜色基于值
R highcharter plot points color based on value
我是 highcharts 和 R highcharter 的新手。
我有一个这样的数据框
tmp <- data.frame(x = 1:5, y = rnorm(5), color = c("green", "red", "green", "orange", "red"))
# x y color
# 1 0.4421 green
# 2 -0.8924 red
# 3 0.8264 green
# 4 0.6695 orange
# 5 -0.0966 red
我想用highcharter画。
对于点的颜色,我想让点的颜色成为数据框中对应的颜色。
我该怎么办?
即使它是 R 代码,任何 JS 解决方案都会很感激,因为我可以用 R 重写它。
如果您以十六进制格式提供颜色变量,highcharter 将识别这些颜色
tmp <- data.frame(x = 1:5, y = rnorm(5), color = c("#00FF00", "#FF0000", "#00FF00", "#ffa500", "#FF0000"))
hchart(tmp, "line", hcaes(x, y, color = color))
稍微改进的解决方案:
set.seed(1)
tmp <- data.frame(x = 1:5, y = rnorm(5),
color = c("green", "red", "green", "orange", "red"))
dummy <- "two"
library(highcharter)
hchart(tmp, type="scatter", hcaes(x=x, y=y, color=color),
marker=list(symbol='circle', radius=5), zIndex=1) %>%
hc_add_series(tmp, type="line", color="lightblue", zIndex=0)
我是 highcharts 和 R highcharter 的新手。 我有一个这样的数据框
tmp <- data.frame(x = 1:5, y = rnorm(5), color = c("green", "red", "green", "orange", "red"))
# x y color
# 1 0.4421 green
# 2 -0.8924 red
# 3 0.8264 green
# 4 0.6695 orange
# 5 -0.0966 red
我想用highcharter画。
对于点的颜色,我想让点的颜色成为数据框中对应的颜色。
我该怎么办? 即使它是 R 代码,任何 JS 解决方案都会很感激,因为我可以用 R 重写它。
如果您以十六进制格式提供颜色变量,highcharter 将识别这些颜色
tmp <- data.frame(x = 1:5, y = rnorm(5), color = c("#00FF00", "#FF0000", "#00FF00", "#ffa500", "#FF0000"))
hchart(tmp, "line", hcaes(x, y, color = color))
稍微改进的解决方案:
set.seed(1)
tmp <- data.frame(x = 1:5, y = rnorm(5),
color = c("green", "red", "green", "orange", "red"))
dummy <- "two"
library(highcharter)
hchart(tmp, type="scatter", hcaes(x=x, y=y, color=color),
marker=list(symbol='circle', radius=5), zIndex=1) %>%
hc_add_series(tmp, type="line", color="lightblue", zIndex=0)