recharts4r

How to add a vertical line in echarts4r chart


I would like to add a vertical lines as showed on the image. Do you have any hint how to do it?enter image description here

df <- data.frame(
        data = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L),
       value = c(10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L))

df %>%   
  e_charts(data) %>% 
  e_area(value) %>% 
  e_tooltip(trigger = "axis") %>% 
  e_toolbox_feature(feature = "dataZoom") %>% 
  e_toolbox_feature(feature = "dataView") %>% 
  e_legend(right = 0) %>% 
  e_format_y_axis(suffix = "%")

Solution

  • You could use e_mark_line with an xAxis value and empty title like this:

    library(echarts4r)
    library(dplyr)
    
    df %>%   
      e_charts(data) %>% 
      e_area(value) %>% 
      e_tooltip(trigger = "axis") %>% 
      e_toolbox_feature(feature = "dataZoom") %>% 
      e_toolbox_feature(feature = "dataView") %>% 
      e_legend(right = 0) %>% 
      e_format_y_axis(suffix = "%") %>%
      e_mark_line(data = list(xAxis = 2), title = "") %>%
      e_mark_line(data = list(xAxis = 6), title = "")
    

    enter image description here

    Created on 2023-10-02 with reprex v2.0.2