Introduction

By Andrew Disher in Interactive Data Visualization R

May 25, 2023

echarts4r : An Overview


echarts4r is by far one of, if not the most, powerful graphing libraries for interactive data visualizations in R that I have come across. Of course, there are many other libraries that provide interactive functionality for data visualizations, like highcharter, developed by Joshua Kunst, and plotly. There is also dygraphs, a great interactive data viz library for time series (something I am particularly passionate about). And of course, we could not talk about interactive graphing without mentioning the incredible geospatial plotting library Leaflet.

As great as highcharter is, it does require a license in order to use the library commercially. Leaflet and dygraphs are both specific to certain types of graphs, even if they do VERY well at what they advertise. Plotly is powerful, and many will point out that it is the best general purpose interactive graphing library available for free. It’s that good. However, I maintain that echarts4r is my favorite interactive graphing library in most situations because it provides nearly as much functionality, if not equally as much, as plotly and, well, it just looks better!

Of course, this is my preference. Someone else could prefer plotly because they greatly value the simplicity and clarity of it, or for some other reason that I have neglected to mention. But I love echarts4r’s style. It looks good, performs well, and provides a great user experience without compromising its ability to effectively communicate data. And, it’s easy to use!

Here are a few examples to wet your tongue.

  1. First up is a relatively straightforward time series graph. It includes bars for the months of the year that indicate the total revenue the company made. The chart also includes a simple trend line. The graph looks typical of a line chart you’d see from other data viz libraries in many ways and the code behind the graph uses relatively few lines. In other words, for very few lines of code you get nicely formatted axes, complete with currency formatting and nicely spaced axis ticks. On top of these simple features, you get a beautiful tooltip on hover and an incredibly useful date filtering bar underneath the graph. Also, when hovering you get a nice highlight effect. And all of this functionality is out-of-the-box!

Times series of revenue by month in 2017 for Northwind Traders

  1. Next up is a beautiful choropleth map created with a few more lines of code. It comes with a zoom feature, customizable to the levels of zoom-in and zoom-out you desire. The familiar tooltip and highlight on hover feature from the time series graph is pressent here as well. The US states are clickable, which produces a fixed label that you can use to compare states that you’re interested in more easily. Lastly, try playing with the color gradient in the bottom left of the graph. It provides nice functionality that you can use to filter the map.

Map of US arrests made for murder per 100,000 residents in 1973

  1. Lastly, I’ll show you a nice looking heatmap. This heatmap is presenting the correlations between the predictor variables I used in a logistic regression project that predicted the health status of a fetus. The letters are used in place of variable names to preserve space. In these types of studies, it’s important to know if your explanatory variables (features, for you machine learning folks) are correlated, since this can have a profound effect on the reliability of whatever model you create with the data. This heatmap provides a nice color gradient, as with the previous visualization, as well as the ever useful tooltips I hope you are getting used to by now (and loving).

Correlation heatmap for fetal health data predictor variables

I hope at least one of these visualizations caught your eye, because these graphs represent just the beginning of what is possible with echarts4r. Far more customization is available for you to take advantage of for the purpose of communicating data more effectively. After all, that is what data visualization is all about.

What can you expect from this series?


The objectives for this series are laid out below:

  • Explore what types of graphs are available.
  • Learn how to use the basic echarts4r syntax.
  • Explore the customization options available. This includes the options that I find generally useful, as well as the method to find how to customize graphs according to your own preferences.

I am creating this series not just to show you some nice graphs and call it a day. We’ll be exploring the entire echarts4r library together and learn how to beautiful data visualizations together. I’ll try to cover not only how to create basic versions of line charts, bar charts, etc., but also how to create more complex visualizations that communicate more complex data concepts.

My goal is to provide a digital resource that compliments the official echarts4r documentation to make it easier for those who want to use this graphing library in their own projects. Ultimately, interactive data visualization is most useful when implemented in data applications or websites. Therefore, I believe that the best next step would be to provide working examples of using echarts4r in Shiny apps. I choose Shiny apps because it is the best framework for creating data applications that I know, is easily available in R, and is what I know best. It is a also another passion of mine that I would love to share with those who care to learn.

If you are interested in learning echarts4r, Shiny, and various other packages/libraries that I like to use on a daily basis with them (like dplyr, tidyr, and other Tidyverse resources) then read on!