Historical US Inflation Rates from 1914

library(rvest)
library(dplyr)
library(lubridate)
library(xts)
inflation_url <- "http://inflationdata.com/inflation/Inflation_Rate/HistoricalInflation.aspx"

# read in the HTML table with the raw data
input.df <-
    read_html(inflation_url) %>%
    html_node("table#GridView1") %>%
    html_table(header = TRUE, trim = TRUE, fill = TRUE, dec = ".") 

# convert character percentages to numeric
inflation.df <- as.data.frame(lapply(input.df, function(x) as.numeric(sub(" %","",x))/100))
inflation.df$Year <- as.integer(inflation.df$Year*100)

mean.inflation <- mean(inflation.df$Ave.*100,na.rm=TRUE)

plot(inflation.df$Year, inflation.df$Ave.*100, pch=20, type="b",
     xlab="Year",ylab="Annual Avg. Inflation Rate")
title("Historical US Inflation Rates Since 1914")

abline(h=0, lty=2, col="black")
abline(h=mean.inflation, lty=2, col="red")
text(1950, mean.inflation,labels=paste0("Overall Average: ", round(mean.inflation, 2), "%"), pos=3, col="red")