# plot_fred_simple.R
plot_fred_simple <- function(df, series1, start, end, series2 = NULL) {
  # Assumes df already has: 
  #   - a column "date" (class Date)
  #   - a column "qdate" (class yearqtr, e.g. "2000 Q1")
  #   - at least one series to plot
  
  # Subsample
  sub <- dplyr::filter(df, qdate >= zoo::as.yearqtr(start),
                       qdate <= zoo::as.yearqtr(end))
  
  # Single plot
  if (is.null(series2)) {
    p <- ggplot2::ggplot(sub, ggplot2::aes(x = date, y = .data[[series1]])) +
      ggplot2::geom_line(color = "blue") +
      ggplot2::labs(title = series1, x = "Date", y = series1) +
      ggplot2::theme_minimal()
    return(p)
  }
  
  # Double plot
  p1 <- ggplot2::ggplot(sub, ggplot2::aes(x = date, y = .data[[series1]])) +
    ggplot2::geom_line(color = "black") +
    ggplot2::labs(title = series1, x = "", y = series1) +
    ggplot2::theme_minimal()
  
  p2 <- ggplot2::ggplot(sub, ggplot2::aes(x = date, y = .data[[series2]])) +
    ggplot2::geom_line(color = "blue") +
    ggplot2::labs(title = series2, x = "Date", y = series2) +
    ggplot2::theme_minimal()
  
  gridExtra::grid.arrange(p1, p2, ncol = 1, heights = c(2,1))
}