Skip to content

Instantly share code, notes, and snippets.

@pschmied
Last active July 29, 2017 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pschmied/bcf3e08e2a231e00ad4b19a16671ccb0 to your computer and use it in GitHub Desktop.
Save pschmied/bcf3e08e2a231e00ad4b19a16671ccb0 to your computer and use it in GitHub Desktop.
Plotting month-over-month change in snap users
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