How to create drill-down graphs with highcharter in R

Victoria D. Doty

Drill-down visualizations can be a good way to current a whole lot of knowledge in a digestible structure. In this case in point, we’ll produce a graph of median home values by U.S. state making use of R and the highcharter package. Sharon Machlis, IDG Preliminary graph of median home […]

Drill-down visualizations can be a good way to current a whole lot of knowledge in a digestible structure. In this case in point, we’ll produce a graph of median home values by U.S. state making use of R and the highcharter package.

Median home values by state Sharon Machlis, IDG

Preliminary graph of median home values by state (best and least expensive 10 states). Info from Zillow.

Each individual state’s bar will be clickable — the drilldown — to see knowledge by county.

Graph of median home values in Massachusetts counties Sharon Machlis, IDG

Right after clicking the bar for Massachusetts, a person sees median home values by Massachusetts county. Info from Zillow.

There are 3 primary steps to building a drill-down graph with highcharter:

  1. Wrangle your knowledge into the required format 
  2. Develop a primary leading-amount graph and 
  3. Insert the drill-down.

If you want to observe together, obtain state- and county-amount knowledge sets for the Zillow Dwelling Benefit Index from Zillow at https://www.zillow.com/investigation/knowledge/. I’m making use of the ZHVI Solitary-Household Homes series.

Initial, load the packages we’ll be making use of:

library(rio)
library(dplyr)
library(purrr)
library(highcharter)
library(scales)
library(stringr)

All can be mounted from CRAN with set up.packages() if you really don’t now have them on your system.

Observe that highcharter is an R wrapper for the Highcharts JavaScript library — and that library is only cost-free for particular, non-professional use (like tests it locally), or use by non-income, universities, or general public educational institutions. For anything at all else, like government use, you need to have to obtain a license. 

Upcoming, I import the state and county CSV data files into R with the subsequent code. (My CSV data files are in a knowledge subfolder of my venture listing.)

states <- import("data/State_zhvi.csv")
counties <- import("data/County_zhvi.csv")

These data files have hundreds of columns, just one for just about every month beginning in 1996. I want to graph the most latest knowledge, so I look for the title of the past column with

names(states)[ncol(states)]

At the time I wrote this, that returned 2020-06-30, which I’ll use as my MedianValue column. I’d like to evaluate that worth to the start off of the century, so I’ll also include things like 2020-01-31 as a PriceIn2000 column.

Info wrangling

Here’s my code for producing a newest_states knowledge frame, which I’ll use as a foundation for the graph:

Copyright © 2020 IDG Communications, Inc.

Next Post

OPA: A general-purpose policy engine for cloud-native

As your group embraces the cloud, you may perhaps locate that the dynamism and scale of the cloud-native stack calls for a considerably far more intricate protection and compliance landscape. For occasion, with container orchestration platforms like Kubernetes gaining traction, builders and devops teams have new accountability above plan regions […]

Subscribe US Now