Creepypasta – Votes vs. Rating (& learning ggplot2)
[This article was first published on everyday analytics, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Excel: Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
R, base package:
R, ggplot:
Am I overfitting? Probably.
Code:
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
# Creepypasta.com stories, Votes vs. Rating | |
# http://www.everydayanalytics.ca/2014/02/creepypasta-learning-ggplot.html | |
library(ggplot2) | |
# Read in the data | |
data <- read.csv(file = 'creepypasta_ratings.csv', header=T, sep=',') | |
# Base Package | |
# Plot | |
plot(data$Rating, data$Votes, pch=16, cex.main=1, cex.axis=0.8, cex=0.8, col=rgb(0,0,1,0.25), log='y', | |
ylab='Votes', xlab='Rating', main='Creepypasta Stories, Votes vs. Ratings') | |
# Fit second order polynomial | |
l <- lm(data$Votes ~ data$Rating + I(data$Rating^2)) | |
points(data$Rating, predict(l), type='l') | |
# equivalent in ggplot | |
gplot <- ggplot(data, aes(Rating, log(Votes))) + | |
geom_point(col=rgb(0,0,1,0.25), pch=16, cex=2) + | |
geom_smooth(method="lm", formula=y~poly(x,2)) + | |
labs(title="Creepypasta Stories, Votes vs. Ratings") + | |
theme_bw() + | |
theme(axis.text=element_text(size=14), axis.title=element_text(size=14), plot.title=element_text(size=16, face="bold")) | |
gplot | |
# Data density with hexbin | |
hexbin <- ggplot(data, aes(Rating, log(Votes))) + | |
stat_binhex() + theme_bw() + | |
theme(axis.text=element_text(size=14), axis.title=element_text(size=14)) | |
hexbin |
References
Source data at Creepypasta.com:
Code on gist:
http://gist.github.com/mylesmharrison/8886272
Creepypasta – in list of internet phenomena (Wikipedia):
http://en.wikipedia.org/wiki/Creepypasta#Other_phenomena
To leave a comment for the author, please follow the link and comment on their blog: everyday analytics.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.