12 December 2016

# Introduction

LAST WEEK I SHOWED YOU 10 TASTY WAYS TO VISUALIZE MORTGAGE RATES, but I’ve got another delicious one for you. Y’all like ribbon candy?

As before we’ll create this chart with R.

## The data

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. See my earlier post for some additional information on the data we’ll use.

Here’s the first few rows of our data:

 date rate year month week 30-year Fixed Mortgage Rate (%) 1 Apr 02,1971 7.33 1971 4 14 2 Apr 09,1971 7.31 1971 4 15 3 Apr 16,1971 7.31 1971 4 16 4 Apr 23,1971 7.31 1971 4 17 5 Apr 30,1971 7.29 1971 4 18 6 May 07,1971 7.38 1971 5 19 7 May 14,1971 7.42 1971 5 20 8 May 21,1971 7.44 1971 5 21 9 May 28,1971 7.46 1971 5 22 10 Jun 04,1971 7.52 1971 6 23 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 data and make our visualization.

## Data prep

We need to do a tiny bit of data preparation which is made quite easy by the data.table() structure.

Now that we have the data ready, we can create our lovely ribbon plot:

## What is this?

This is a composite chart consisting of:

1. A line
2. Two ribbons
3. A marginal rugplot at the bottom

### The line

The line is just a standard time series line created with geom_line() showing weekly average mortgage rates. There’s nothing particularly special about it, but it’s the anchor that lets us make sense of the rest of the plot.

### Two ribbons

The ribbons, shaded purple and green, show a trailing 52-week min and max for the interest rate. Together they show the range for the interest rate in the past year. Let’s look at just the last row of our data set:

 date rate year month week rmax.52 rmin.52 rup rdown 30-year Fixed Mortgage Rate (%) 2385 Dec 08,2016 4.13 2016 12 49 4.13 3.41 3.41 4.13 Source: Freddie Mac Primary Mortgage Market Survey

Here we see that for the week of December 8, 2016 the average mortgage rate was 4.13 percent. The 52-week max was also 4.13 percent. The 52-week min was 3.41 percent. This means that over the 52-week window ending December 8, 2016 mortgage rates ranged as low as 3.41 percent and as high as 4.13 percent. Because the last observation is equal to the 52-week max there’s no green shaded area for this week, but it’s all purple in the plot, extending down from 4.13 percent to 3.41 percent.

We can plot just the line and ribbons for the weeks in 2016:

We see a lot of green for most of 2016, indicating that for much of the year mortgage rates were substantially below where they were 52-weeks ago.

### The rug really ties the whole plot together.

What’s the point of the rug? Well, it really ties the plot together.

Consider the plot below which shows just rates for 2016, but adds in the rug plot:

The rug is colored to correspond to the where the black line is in relation to the edges of the shaded areas. If the current rate (black line) is at the max so that there is no green area, then the tick will be dark purple. If the current rate is at the 52-week min so that there is no purple area then the tick will be yellow.

Zooming out, we can see that the rug shows us at a glance how rates have been trending on a year-over-year basis.

Now we’ve triple-encoded the range of rates in this chart. The line captures the trend, the purple ribbon indicates rates are rising relative to a year ago, while green shading indicates rates have been falling over the past year. Likewise the ribbon at the bottom, which is conveniently placed near the x axis, displays the current rate relative to 52-week min and max.