All functions of the echarts4r package start with e_, and all its Shiny proxies end with _p. All echarts4r plots are initialised with e_charts.

Your first plots

Use the %>% operator to add plots and options.

mtcars %>% 
  e_charts(wt) %>% # initialise
  e_line(qsec) %>% # add line
  e_area(mpg) %>% # add area
  e_x_axis(min = 1) # change x axis minimum

Customise the lines to make them smooth.

mtcars %>% 
  e_charts(wt) %>% # initialise
  e_line(qsec, smooth = TRUE) %>% # add smooth line
  e_area(mpg, smooth = TRUE) %>% # add area
  e_x_axis(min = 1) # change x axis minimum

qsec and mpg isn’t clear to reader, rename them, also rename the x axis while you’re at it.

mtcars %>% 
  e_charts(wt) %>% # initialise
  e_line(qsec, smooth = TRUE, name = "1/4 mile time") %>% # add smooth line
  e_area(mpg, smooth = TRUE, name = "Miles/gallon") %>% # add area
  e_x_axis(min = 1, name = "weight") # change x axis minimum

Use one of the 13 built-in themes, see ?e_theme for a complete list, also add a title with e_title.

mtcars %>% 
  e_charts(wt) %>% # initialise
  e_line(qsec, smooth = TRUE, name = "1/4 mile time") %>% # add smooth line
  e_area(mpg, smooth = TRUE, name = "Miles/gallon") %>% # add area
  e_x_axis(min = 1, name = "weight") %>%  # change x axis minimum
  e_title("Ol' mtcars example") %>%  # Add title
  e_theme("infographic") # theme

The legend and title are a bit close, let’s move one of the legend to another part the canvas.

mtcars %>% 
  e_charts(wt) %>% # initialise
  e_line(qsec, smooth = TRUE, name = "1/4 mile time") %>% # add smooth line
  e_area(mpg, smooth = TRUE, name = "Miles/gallon") %>% # add area
  e_x_axis(min = 1, name = "weight") %>%  # change x axis minimum
  e_title("Ol' mtcars example") %>%  # Add title
  e_theme("infographic") %>%  # theme
  e_legend(bottom = 0) # move legend to the bottom

Add a tooltip, for which there are numerous options, here we use trigger = "axis" triggered by the axis rather than a single data point.

mtcars %>% 
  e_charts(wt) %>% # initialise
  e_line(qsec, smooth = TRUE, name = "1/4 mile time") %>% # add smooth line
  e_area(mpg, smooth = TRUE, name = "Miles/gallon") %>% # add area
  e_x_axis(min = 1, name = "weight") %>%  # change x axis minimum
  e_title("Ol' mtcars example") %>%  # Add title
  e_theme("infographic") %>% # theme
  e_legend(bottom = 0) %>% # move legend to the bottom
  e_tooltip(trigger = "axis") # tooltip

You can also customise the axis with e_axis or its sister functions, e_x_axis and e_y_axis. There are also helper functions like e_format_axis to easily add suffixes or prefixes to your axis labels.

mtcars %>% 
  e_charts(wt) %>% # initialise
  e_line(qsec, smooth = TRUE, name = "1/4 mile time") %>% # add smooth line
  e_area(mpg, smooth = TRUE, name = "Miles/gallon") %>% # add area
  e_x_axis(min = 1, name = "weight") %>%  # change x axis minimum
  e_title("Ol' mtcars example") %>%  # Add title
  e_theme("infographic") %>% # theme
  e_legend(bottom = 0) %>%  # move legend to the bottom
  e_tooltip(trigger = "axis") %>%  # tooltip
  e_format_y_axis(suffix = "mpg")

The package now understands dplyr::group_by in order to avoid having to add many layers manually. Let’s say we have a data.frame containing data for 10 groups, we can just dplyr::group_by instead of adding, say, 20 e_line.

You’re in on the basics, go to the advanced section or navigate the site to discover how add multiple linked graphs, draw on globes, use the package in shiny, and more.