Plot in R with echarts4r

Learn how to make everything from basic line graphs to racing bar charts — all interactive and easily animated — with the echarts4r R package.

1 2 Page 2
Page 2 of 2

Data instructions

Head to https://www.zillow.com/research/data/ and download the ZHVI Single-Family Home Time Series by city and the ZHVI Condo/Co-op Time Series by city. Then run the following:

library(data.table)
library(dplyr)
library(echarts4r)
process_file <- function(filename, hometype) {
mydata_all <- data.table::fread(filename)
mycols <- grep("((2007)|(2008)|(2009)|(201.)|(202.))-12-", names(mydata_all), value = T)
mydata_all[, RegionID := as.character(RegionID)]
myregionids <- c("38128", "10221", "24043", "44269", "6181", "20330", "17426", "40326", "41176")
mydata <- mydata_all[RegionID %chin% myregionids, c("RegionName", mycols), with = FALSE]
setnames(mydata, "RegionName", "City")
mydt <- melt(mydata, id.vars = "City", variable.name = "Month", value.name = "Value")
mydt[, Region := fcase(
City %chin% c("New York", "Boston"), "Northeast",
City %chin% c("Dallas", "Austin", "Charlotte", "Tampa"), "South",
default = "Other"
)]
setorder(mydt, City)
mydt[, HomeType := hometype]
return(mydt)
}
houses <- process_file("data/City_zhvi_uc_sfr_tier_0.33_0.67_sm_sa_mon.csv", "SingleFamily")
houses_wide <- dcast(houses[, c("City", "Month", "Value")], Month ~ City)
condos <- <- process_file("data/City_zhvi_uc_condo_tier_0.33_0.67_sm_sa_mon.csv", "Condo")

Copyright © 2021 IDG Communications, Inc.

1 2 Page 2
Page 2 of 2
How to choose a low-code development platform