I’m trying to plot a graph with two colors according if it is positive or negative values, using highchart in R. I simplify a code in the next way:
x <- c(-3, -4, 1, 4, 8)
dt <- seq(as.Date("2018-01-01"), as.Date("2018-01-05"), by = "days")
ts <- xts(x, dt )
names(ts)="serie"
print(ts)
highchart(type="stock") %>%
hc_add_series(ts$"serie",
type = "lollipop",
color="black")
I’m trying to plot the graph with black color for positive values and green color for negative ones. I checked that we can use negativeColor in JS, ¿is there a way to use this on R? For example in JS: https://jsfiddle.net/BlackLabel/9ay8vezd/
>Solution :
You could simply add negativeColor = 'green' as an argument to hc_add_series:
library(highcharter)
x <- c(-3, -4, 1, 4, 8)
dt <- seq(as.Date("2018-01-01"), as.Date("2018-01-05"), by = "days")
ts <- xts::xts(x, dt )
names(ts)="serie"
highchart(type="stock") %>%
hc_add_series(ts$"serie",
type = "lollipop",
color = 'black',
negativeColor = 'green')
