Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NegativeColors in Highcharts with R

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/

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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') 

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading