IN ORDER TO HELP PEOPLE UNDERSTAND WHAT’S GOING ON with the economy, housing and mortgage markets I spend a great deal of time thinking about interest rates. Interest rates, specifically mortgage rates are very important to housing and mortgage markets. In my professional life I work on tracking trends in housing and mortgage markets, and that includes mortgage rates. I create a lot of visualizations of mortgage rates.
In this post I’m going to share with you 10 of my favorate ways to visualize mortgage rates and give you R code to do it.
The data I’m going to use are estimates of weekly U.S. average 30-year fixed mortgage rates from the Primary Mortgage Market Survey from Freddie Mac. These data can be easily downloaded from the St. Louis Fred database here.
I have the data saved in a simple text file with a column for data, the mortgage rate, and helper columns week, month, and year, where week is the week number starting with the first week of the year.
Let’s load the data and take a peek.
30-year Fixed Mortgage Rate (%)
Source: Freddie Mac Primary Mortgage Market Survey
The data are weekly observations on mortgage rates running from April 2, 1971 through December 8, 2016. Now let’s take these series and make 10 different visualizations. We’ll start simple, and build up to more complex visualizations.
A note on data manipulations
I’m going to be using the data.table() package from R. I’ve found this package very helpful for doing the types of data manipulations I most frequently need. Check the comments in the code below for specific callouts.
1: A simple line chart
Let’s start simple with a line chart. We’ll also add some styling including a reference line at the last monthly observation and a dot at the last point. We’ll start the data in 2001.
2: Line chart comparing weeks by year
This next chart is a variation on the line chart. Instead of using date for the x axis, we use the week of the year and plot a separate line for recent years (2013, 2014, 2015 and 2016). By comparing the lines at any point on the x axis, we can see where rates were one or more years ago on this week.
3: Area chart showing year-over-year changes
In this next chart we’re going to compute a rolling 52-week difference. We also want to shade in the area between the line difference colors based on whether or not rates are up or down. Shading between two lines in ggplot is tricky, so I’m going to actually create two series, one for positive 52-week changes and another for negative 52-week changes.
4: Combo line with rugplot
We can enhance this plot by adding a marginal rug plot to the bottom of the chart indicating whether or not rates are up or down for that week.
5: Step function
We can use a step function to compare the annual average to the weekly values. What we’ll do in this plot is compute the annual average (using data.table()) and plot it as a step function on top of the line chart from 1.
6: Pie Chart
We can also make a Pie chart:
Ha ha, just kidding, that’s awful!
7: Strip chart
I just tried this chart out today and I really like it. It’s a strip chart that shows the year-over-year percent change in mortgage rates. You can’t read the information as accurately as a line chart, but it gives you a much better impression on how rates have been changing. Let’s make it and then discuss more:
While you can’t read the values from this chart as clearly as a line chart (or a table), you can quickly get a feel for the important trends in the data. The bright yellow periods are when mortgage rates were rising, while the dark purple corresponds to periods when rates were falling. It’s pretty easy to see that 2001, 2003, 2009 and 2012 were years when rates fell a lot, while 2006, 2013, and 2014 were when rates were rising relative to the previous year.
8: Animated Line Chart
These next three charts are animated versions of some the preceding charts. We’ll start with a simple animated line chart from 1.
9: Animated Line Chart 2
We can also construct an animation for the weekly comparison line chart:
10: Animated line chart with annotations
We can also add some annotations and some more detailed camerawork for the animated linechart.
The way we’ll do it, is set up a function that takes two input dates, a minimum and a maximum. The data will then get truncated at the min and max dates, allowing us to zoom around the time series history of mortgage rates.
For smoother animations we’ll use tweenr.See my earlier post about tweenr for an introduction to tweenr, and more examples here and here.
I’ve got several other visualizations I use from time to time. Check back in this space for more.