rvisualizationecharts4r

e_mark_line symbol and name


How can I change the label of the line generated with e_mark_line? Here is my attempt, instead of showing the number 200, I'd like it to have my own label.

library(echarts4r)
library(tidyverse)    

line <- list(
        xAxis = 200
        , name = "label 1"
    )

USArrests %>% 
  e_charts(Assault) %>% 
  e_scatter(Murder, Rape) %>% 
  e_mark_line(data = line, symbol = "none", name = "label 2")

Chart generated by code


Solution

  • The underlying echarts JavaScript to mark lines, points and areas is rather convoluted. The title must be specified in the data. In the dev version there are convenience title related arguments.

    library(echarts4r)
    
    cars %>% 
      e_charts(speed) %>% 
      e_scatter(dist, symbol_size = 5) %>% 
      e_legend(FALSE) %>% 
      # manual
      e_mark_line(data = list(xAxis = 7, symbol = "rect", label = list(formatter = "tortoise"))) %>%
      # convenience arguments in latest github version
      e_mark_line(data = list(xAxis = 12), title = "Speed Limit") %>% 
      e_mark_line(data = list(xAxis = 22), title = "Need for Speed")