Hello,
I use the Highcharter lib to make my graphs in my R projects.
I recently used the plotbands feature which allows me to have horizontal areas on my graph
hc<-hchart(donnees,"spline",hcaes(x=mois, y=moy, group=origine))%>%
hc_title(text = titre, align="center")%>%
hc_tooltip(
crosshairs = TRUE,
borderWidth = 5,
sort = TRUE,
table = TRUE)%>%
hc_yAxis(
title = analyse,
min = 0,
plotBands = list(
list(
from = 0,
to = 1000000,
color = "rgba(0, 200, 0, 0.1)",
label = list(text="texte 1")
),
list(
from = 1000000,
to = 1250000,
color = "rgba(0, 255, 255, 0.1)",
label = list(text="texte 2")
),
list(
from = 1250000,
to = 1500000,
color = "rgba(50, 0, 0, 0.1)",
label = list(text="texte 3")
),
list(
from = 1500000,
to = 2000000,
color = "rgba(250, 255, 0, 0.1)",
label = list(text="texte 4")
),
list(
from = 2000000,
to = 3000000,
color = "rgba(255, 150, 0, 0.1)",
label = list(text="texte 5")
),
list(
from = 3000000,
to = 5000000,
color = "rgba(250, 0, 0, 0.1)",
label = list(text="texte 6")
)
))%>%
hc_colors(c("#203d7d","#a0a0ed","#203d7e","#FF3333","#4EFF00"))%>%
hc_exporting(enabled = TRUE,filename = paste0('export - ',titre))%>%
hc_add_theme(hc_theme_economist())
Now I would like the "plotbands" part to be dynamic both in terms of the number of zones (I can have 2,3,4...), and in the parameterization of these zones.
I have all the necessary data in database, I know how to recover them in a dataframe.
below I have a dataframe with 4 lines to make my 4 zones
lib point lim_bas lim_haut
1 A 0 0 50000
2 B -3 51000 100000
3 C -20 101000 200000
4 D -50 201000 999999