Highcharts is hugely popular for its professional appearance and smooth animations. Highcharts is only free to use for non-commercial organisations - there's a good discount available for users of the highcharter library Highcharts is excellent at ensurin
- [Instructor] The Highcharter library allows us to create beautiful, very clean interactive charts, plots, and even some maps. Let's look at some examples of what I can build. In our exercise files, we have a file called example-charts.R. Let me just minimize my environment here. Let's load these libraries at the top of the script file, the tidyverse, lubridate, highcharter, and oidncharts. Then line seven through 14, I used dplyr verbs on line eight and nine to group and summarize my data, and then on line 11 through 14, I used highcharter to generate me this group bar chart.
It's very easy to stack bars in a bar chart using highcharter by just specifying stacking and stack to plotOptions. So here, we can see a stack bar chart, and it's also very simple to create a percentile stacks bar chart, as we can see, on lines 26 through 35. Plotly also allows us to build scatter charts. It's not very good with thousands of data points. But with a couple of hundred data points, it's really quite smooth and fast.
So here on line 39 through 43, I create a scatter plot. We can also create line charts just as easily on line 46 through 51. Highcharter is also awesome for creating interactive time series. I'm just going to load up a data set from the online_labour_index.csv file. In line 57 through 64, I'll create a highchart object of a type stock. Here we can see our interactive time series with a tooltip as I move through the data, and I also have a window here that allows me to slice through to a specific date range, or I could say I want to zoom in to the last six months.
It's also possible to create choropleth easily with highcharter. So if I just load the jsonlite library and the gapminder library in 67, 68, load in my geoJSON file, filter the gapminder data set to only include the most recent year. And then line 75 through 84, generates me a choropleth of my data. One final chart I want to mention, because highcharter is very good at it, is tree maps. So let's go to Files, let's open treemap.R.
What can we do with these interactive charts? Well, like all HTML widgets, we can easily include these outputs in RMarkdown documents, or even in Shiny apps. So how does Highcharter compare to other options for visualizing data? Well, Highcharter is an extremely professional and clean-looking visualization tool. You may actually recognize Highchart outputs from some of the data journalism sites like fivethirtyeight.com or any of these customers of Highcharts that Highcharts proudly display on their own website.
Highchart is deliberately designed from the ground up to be mobile responsive and responses, and this translates into the Highcharter library as well. As a consequence of its mobile friendliness, there're fewer onscreen tools available in the Highcharter objects than there is in something like Plotly for instance. Highcharts also compartmentalizes itself much more than other libraries. There's a separate API in a Highcharter for each type of chart, where type means chart, maps, or stack chart, which includes the time series chart we saw before, and more specialist financial visualizations like candlestick charts.
Highchart is not free for commercial or governmental use. There is, however, a non-commercial license available for personal, education, or not-for-profit purposes. I recommend you consult to Highchart's website FAQ to see which license is appropriate for your case. One last thing I will say about the license. There is a discount available in individual commercial licenses for uses of the Highcharter library. I have personal experience with Highcharter performing a little bit slowly with relatively medium sized data sets, over a few thousand elements.
My advice for where you need to work with lots of data is first try and trim unnecessary columns in the data you send to Highcharter. If you have columns you're not displaying or using in the chart, remove them with the select verb from dplyr. If you need further performance boosts, try and use low-level functions for inserting data into Highcharter, as opposed to the hcaes function. Finally, you might want to investigate using the highchart2 function, which implements the boost.js library designed to radically improve Highchart's performance.
However, the development version of the library on GitHub does have this functionality, and it's fairly trivial to backport it. There's an example of how to do that in this video's exercise files. Let's jump back to our studio. I'll move to my file explorer. I'll select server.R, and let's run this Shiny app by clicking Run App. So here we have a relatively simple looking scatter plot from Highcharter. We can see when I move my cursor over markers, I get information about the mouseOvered point.
Start by learning to manage packages and structure data for visualizations with the tidyverse and the pipe operator. Then there is an important question: Which library should you choose? The course introduces five popular options: Leaflet, Plotly, Highcharter, visNetwork, and DataTables (DT). Instructor Martin Hadley shows how to use these libraries to create scattergeo, choropleth, and geolines maps; stacked bar charts, scatter charts, bubble charts, and heat maps; treemaps and time series charts; interactive networks and graphs; and responsive, interactive data tables. Plus, learn how to customize your visualizations with legends and tooltips, and extract click information for Shiny apps.
- Installing htmlwidgets
- Selecting the best htmlwidget
- Creating interactive maps with Leaflet
- Creating interactive charts with Plotly and Highcharter
- Creating interactive networks with visNetwork
- Creating interactive tables with DT