Skip to content

Instantly share code, notes, and snippets.

@t-redactyl
Last active September 27, 2017 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save t-redactyl/7c6875812dae4f3489a7 to your computer and use it in GitHub Desktop.
Save t-redactyl/7c6875812dae4f3489a7 to your computer and use it in GitHub Desktop.
set.seed(567)
# Sample of 30 (29 from the Poisson distribution and an outlier of 260)
sample1 <- c(rpois(29, lambda = 220), 260)
# Sample of 10 (9 from the Poisson distribution and an outlier of 260)
sample2 <- c(rpois(9, lambda = 220), 260)
# Simulate some data for 2014, with mean page views of 220 per day.
days <- seq(as.Date("2014/1/1"), as.Date("2014/12/31"), "days")
page.views <- rpois(365, lambda = 220)
views <- data.frame(days, page.views)
# Generate post Christmas sale peak period (January 1-10) with mean page views of 400 per day.
views$page.views[views$days >= "2014/01/01" & views$days <= "2014/01/10"] <- rpois(10, lambda = 400)
# Generate Easter peak period (April 1-21) with mean page views of 350 per day.
views$page.views[views$days >= "2014/04/01" & views$days <= "2014/04/21"] <- rpois(21, lambda = 350)
# Generate Black Friday and Christmas peak periods (November 28-December 31) mean page views of 500 per day.
views$page.views[views$days >= "2014/11/28" & views$days <= "2014/12/31"] <- rpois(34, lambda = 500)
require(ggplot2); require(knitr); require(magrittr)
opts_chunk$set(fig.path='/figure/',echo=FALSE, warning=FALSE, message=FALSE)
qplot(days, page.views, data = views, geom = "line") %>%
add(geom_line(colour = "#4271AE")) %>%
add(ggtitle('Website Page Views in 2014')) %>%
add(xlab('')) %>%
add(ylab('Daily page views')) %>%
add(geom_hline(yintercept=220, linetype="dashed")) %>%
add(theme_bw())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment