df1 <- read_csv('"x","y", "text"
27.98,255, "Arbois"
45.5,611,"Montrond"
63,651,"Mont-sur-Monnet"
84,789,"Bonlieu"
129.5,382,"Chassal"
159,443,"Saint-Claude"')
df2 <- read_csv('"x","y","text"
101.44,1026,"Col de la Joux"
138.5,748,"Côte de Viry"
176.4,1202,"Montée de la Combe<br>de Laisia Les Molunes"')
df3 <- read_csv('"x","y","text"
96.2,783,"6.1 km climb<br>4.6% on avg."
134.5,540,"7.6 km climb<br>5.2% on avg."
172.2,925,"11.7 km climb<br>6.4% on avg."
')
df_to_annotations_labels <- function(df, xAxis = 0, yAxis = 0) {
stopifnot(hasName(df, "x"))
stopifnot(hasName(df, "y"))
stopifnot(hasName(df, "text"))
df %>%
rowwise() %>%
mutate(point = list(list(x = x, y = y, xAxis = 0, yAxis = 0))) %>%
select(-x, -y)
}
df1_p <- df_to_annotations_labels(df1)
df2_p <- df_to_annotations_labels(df2)
df3_p <- df_to_annotations_labels(df3)
hc21 %>%
hc_annotations(
list(
labelOptions = list(backgroundColor = 'rgba(255,255,255,0.5)', verticalAlign = "top", y = 15),
labels = list_parse(df1_p)
),
list(
labels = list_parse(df2_p)
),
list(
labelOptions = list(
shape = "connector",
align = "right",
justify = FALSE,
crop = TRUE,
style = list(fontSize = "0.8em", textOutline = "1px white")
),
labels = list_parse(df3_p)
)
) %>%
hc_caption(
text = "Este gráfico utiliza la función Anotaciones de Highcharts para colocar
etiquetas en varios puntos de interés. Las etiquetas son <i>responsivas</i> y se ocultarán
para evitar la superposición en pantallas pequeñas."
)