Len Kiefer

Helping people understand the economy, housing and mortgage markets

dcasting a data table

Been a while since I blogged here. Where does time go? On Twitter, I realized it’s just about time for spooky plots: U.S. existing home sales hit a seasonally adjusted annual rate of 6 million in August 2020, first time at 6 million since 2006 pic.twitter.com/4ZKrO2d0zN — 📈 Len Kiefer 📊 (@lenkiefer) September 22, 2020 Maybe too early? In this post, I want to share a simple R code pattern that’s been useful for me.

Using darklyplot

Yesterday I announced that I wrote a simple R package darklyplot. This is a vignette I have built to help explain ways you can use the package. The goal of darklyplot is to create simple time series plots with a dark background. The miniminum and maximum values are highlighted, and color coded along with the y axis and x axis labels. This vignette walks through basic usage and explores some of the package options.

A new R package darklyplot

Today I try my hand at building an R package called darklyplot. This package is a little extension of ggplot2 to create a dark themed time series plot. This packages lets you create simple dark-theme times series plots. It extends ggplot2 and relies on mdthemes to make color coded axis labels. The axis labels use ggthemes::geom_rangeframe to create Tufte-like axes. Through parameters, the user can alter the colors, include shading under the line, and also add a single reference line.

Gradient shading with ggplot2

Over on Twitter Grant McDermott shares a neat ggplot2 trick: A shortcut I like to use is calling multiple geoms in an lapply() call, since this automatically generates a list. Works well for investigating plotting variations, e.g. ggplot(diamonds, aes(carat)) + lapply(c(50,200), function(b) geom_histogram(bins=b, alpha=0.3)) https://t.co/hf0vtvDkbk pic.twitter.com/jmmqlyJEKo — Grant McDermott (@grant_mcdermott) June 22, 2020 I applied this trick to create a gradient fill for a chart. Looks kind of like Kool-Aid.

The Coronavirus Recession

Coronavirus Recession Over on LinkedIn I posted a summary of recent economic talks I have been giving: The Coronavirus Recession. Read the whole things for analysis and lots of charts, but I leave off with three key questions: Recession was here, but is it already gone? Housing market indicators have rebounded, but will the recovery be sustained? After effects of shutdown and possible second wave to the pandemic remain as risks to the outlook, how big are these risks?

Presentation Quadfecta and Jobs Friday June 2020

Yesterday I completed the elusive presentation quadfecta. I did a talk on Zoom, Teams, WebEx and Skype. These communication apps are great, but after a few hours of maintaining “resting Zoom face” (you want to look interested as the camera is always rolling), I felt a bit exhausted. But it was totally worth it. The highlight for me was being able to join Jeffrey Shaffer, Steve Wexler, Amanda Makulec, and Andy Cotgreave for Chart Chat.

State unemployment rate dataviz

A couple years ago I posted R code for a remix of a remix of a US state unemployment rate chart. Post Working on a workout. Some of the images were lost in a blog transition. We’ll update below. Here’s an updated version: And another remix focusing just on April 2020 (latest data). R code ###################### ## Load Libraries ## ###################### library(data.table) library(quantmod) library(tidyverse) library(geofacet) # Download data big file ur.

Tornado Charts

Earlier this week, I made a boss chart: https://t.co/6wf40jtqHI pic.twitter.com/xlv3Uzpiv0 — 📈 Len Kiefer 📊 (@lenkiefer) May 12, 2020 While listening to Chart Chat I heard Jeffrey Shaffer, Steve Wexler, Amanda Makulec, and Andy Cotgreave discuss tornado charts. I decided it might be a good idea to make one. Because I’m not sure I can trust with the awesome power inherent in these charts I won’t post R code here.

Mortgage rates hit a record low

This week the Freddie Mac Primary Mortgage Market Survey reported a record low for the U.S. weekly average 30-year mortgage rate. First some charts, then below I post R code. R code Load libraries library(fredr) library(tidyverse) library(patchwork) library(cowplot) library(gganimate) library(lubridate) # updated You’ll need a custom color scale (see below for code). R code to wrangle data data preparation code source(paste0(mydir,"len_color_scales.R")) #custom color scale code copied below fredr_set_key("YOURKEY") df <- fredr(series_id = "MORTGAGE30US", observation_start = as.