I want to produce a column chart with highcharts in R which would display the values larger than 0 in blue color and values less than 0 in red. Is there any straightforward way of doing this?
My chart code is simple as this:
hchart(
df_temps,
"column",
hcaes(x = Device, y = Temperature))
The data (df_temps) looks like this:
Device Temperature
A -0.78
B 14.8
Thank you very much for any suggestions.
For your example, this would work:
df_temps <- data.frame(Device = c("A","B"), Temperature = c(-0.78,14.8))
hchart(
df_temps,
"column",
hcaes(x = Device, y = Temperature, color=c("#910000","#2f7ed8")))
More generally and "condition-based":
df_temps <- data.frame(Device = c("A","B"), Temperature = c(-0.78,14.8))
df_temps$col <- ifelse(sign(df_temps$Temperature)==-1, "#910000","#2f7ed8")
hchart(
df_temps,
"column",
hcaes(x = Device, y = Temperature, color=col))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments