Skip to content

Instantly share code, notes, and snippets.

@klahrich
Created May 31, 2016 23:31
Show Gist options
  • Save klahrich/eb3b56f8926e9ce2513c32b499fcee25 to your computer and use it in GitHub Desktop.
Save klahrich/eb3b56f8926e9ce2513c32b499fcee25 to your computer and use it in GitHub Desktop.
library(rvest)
library(magrittr)
library(dplyr)
library(purrr)
library(lubridate)
library(tidyr)
library(ggplot2)
library(scales)
setwd("...working directory...")
#html page of the sonicpi google group
html <- read_html("sonicpi.html")
table <- html %>%
html_nodes(".IVILX2C-p-V") %>%
html_table() %>%
`[[`(1)
f <- safely(mdy)
d1 <- f(table$X3)[[1]]
d1[is.na(d1)] <- mdy(paste(table$X3[is.na(d1)], 2016))
d1[is.na(d1)] <- today()
table$date <- d1
table$posts <- extract_numeric(table$X2)
table_monthly <- table %>%
group_by(month=as.Date(cut(.$date, breaks="month"))) %>%
summarise(posts = sum(posts))
ggplot(data=table_monthly, aes(x=month, y=posts)) +
geom_bar(stat="identity", fill="deeppink1") +
scale_x_date(date_labels="%Y-%m", date_breaks="1 month", limits=c(as.Date("2013-09-01"), as.Date("2016-06-01"))) +
labs(y="# posts per month", title="# of posts on sonic-pi google groups") +
geom_smooth(se=FALSE, linetype=5, col="gray65") +
theme(axis.text.x = element_text(angle=90, vjust=0.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment