daily pastebin goal
12%
SHARE
TWEET

Untitled

coltonpeltier Jan 18th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(ggplot2)
  2. library(tidyverse)
  3.  
  4. since2k <- read.csv(PathToCSVFile, header = T)
  5.  
  6. # Format the date column
  7. since2k$Date <- strptime(since2k$Date, format = "%b %d %Y")
  8.  
  9. # Format Date
  10. since2k$Date <- as.POSIXct(since2k$Date)
  11.  
  12. yearSeq <- seq(1970,2018,1)
  13.  
  14. yearsSumm <-
  15.   tibble(year = numeric(), gdpAvg = numeric())
  16.  
  17. for (year in 1:length(yearSeq)) {
  18.   yearString <- paste0(yearSeq[year],"-01-01")
  19.   dt <- as.POSIXct(yearString,tz="EST")
  20.  
  21.   reducedData <-
  22.     since2k %>%
  23.     filter(Date > dt)
  24.  
  25.   yearsSumm <-
  26.     yearsSumm %>%
  27.     add_row(year = yearSeq[year], gdpAvg = mean(reducedData$Value))
  28. }
  29.  
  30. yearsSumm <-
  31.   yearsSumm %>%
  32.   mutate(since2008 = ifelse(year == 2008, TRUE, FALSE))
  33.  
  34. ggplot(yearsSumm) +
  35.   geom_point(aes(x=year,y=gdpAvg, colour = since2008)) +
  36.   geom_hline(yintercept = mean(yearsSumm$gdpAvg), linetype=4) +
  37.   guides(colour = F) +
  38.   labs(x="Year",
  39.        y="Average Yearly GDP")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top