Last active
July 29, 2017 15:51
-
-
Save pschmied/bcf3e08e2a231e00ad4b19a16671ccb0 to your computer and use it in GitHub Desktop.
Plotting month-over-month change in snap users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) # Start with the tidyverse, yo! | |
library(lubridate) # Hey mate, use lubridate! | |
df <- tibble( # Like data.frame, but tidyverse...ier | |
month = month(1:12, label = 12), | |
cases = c( | |
2291999, 2295025, 2305049, 2298570, | |
2312778, 2322623, 2323876, 2335145, | |
2324974, 2327760, 2363594, 2394956) | |
) %>% # Pipes are part of tidyverse / common in modern R | |
mutate( | |
monthly_change = c(0, diff(cases)) | |
) | |
plot_monthly_change <- ggplot(df, aes(x = month, y = monthly_change)) + | |
geom_density() | |
ggsave("snap_monthly_change.pdf", plot_monthly_change, width = 10, height = 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment