Update
If you prefer using just one hc_add_series
, consider utilizing zones
in conjunction with a specified zoneAxis
. Within the designated zone
, define the desired value
and color
based on the range of your chosen zoneAxis
, x or y. In this instance, it pertains to x, specifically pinpointing the year 1990. Below is an illustrative example:
library(tidyverse)
library(gapminder)
library(highcharter)
highchart() %>%
hc_add_series(
data = gapminder %>% filter(country == 'Chile'),
hcaes(x = year, y = pop),
type = 'line',
zoneAxis = 'x',
zones = list(list(value = 1990, color = 'red'), list(value = 1990, color = 'blue'))
)
https://i.sstatic.net/oPQpB.png
Generated on 2022-10-07 utilizing reprex v2.0.2
You have the option to create two hc_add_series
instances with distinct filter
conditions. The issue might arise from the absence of data for the year 1990, so here's an alternative approach:
library(tidyverse)
library(gapminder)
library(highcharter)
highchart() %>%
hc_add_series(
data = gapminder %>% filter(country == 'Chile' & year <= 1990),
hcaes(x = year, y = pop),
color = 'red',
type = 'line'
) %>%
hc_add_series(
data = gapminder %>% filter(country == 'Chile' & year > 1990),
hcaes(x = year, y = pop),
color = 'blue',
type = 'line'
)
https://i.sstatic.net/Pw4Tx.png
highchart() %>%
hc_add_series(
data = gapminder %>% filter(country == 'Chile' & year <= 1992),
hcaes(x = year, y = pop),
color = 'red',
type = 'line'
) %>%
hc_add_series(
data = gapminder %>% filter(country == 'Chile' & year > 1991),
hcaes(x = year, y = pop),
color = 'blue',
type = 'line'
)
https://i.sstatic.net/IQ6OX.png
Generated on 2022-10-02 utilizing reprex v2.0.2