Created
April 15, 2017 08:05
-
-
Save t-redactyl/d45d800566c00b34aa6f849fb1e975af to your computer and use it in GitHub Desktop.
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(ggplot2) | |
positions = c("Travel and Holidays", "Finances", "Learning and Career", "Mental Wellbeing", | |
"Relationships", "Physical Health") | |
# What are the most popular resolutions? | |
p1 <- ggplot(twitter_df[twitter_df$Resolution.type != "",], aes(x = Resolution.type, fill = Resolution.type)) + | |
geom_bar() + | |
coord_flip() + | |
ggtitle("Number of tweets by resolution type") + | |
scale_x_discrete(limits = positions, name = "") + | |
scale_y_continuous(name = "Number of tweets") + | |
scale_fill_brewer(palette = "Paired") + | |
theme_bw() + | |
theme(plot.title = element_text(size = 12, family = "Tahoma", face = "bold"), | |
text = element_text(size = 10, family = "Tahoma")) + | |
labs(fill = "Resolution") + | |
geom_text(stat = "count", aes(label = ..count..), | |
family = "Tahoma", size = 3, hjust = 1) | |
p1 | |
# How do people feel about their resolutions? | |
p2 <- ggplot(data = twitter[twitter$Resolution.type != "" & twitter$Compound != 0,], | |
aes(x = Compound, colour = Resolution.type)) + | |
geom_density(position="identity", fill = NA, size = 0.8) + | |
ggtitle("Density plots of overall sentiment by resolution type") + | |
scale_x_continuous(name = "Compound sentiment score") + | |
scale_y_continuous(name = "Density") + | |
scale_colour_brewer(palette = "Paired") + | |
theme_bw() + | |
theme(plot.title = element_text(size = 12, family = "Tahoma", face = "bold"), | |
text = element_text(size = 10, family = "Tahoma"), | |
legend.position="none") + | |
facet_wrap( ~ Resolution.type, ncol=2) | |
p2 | |
# Get median compound resolutions | |
library(knitr) | |
kable(aggregate(Compound ~ Resolution.type, | |
data = twitter[twitter$Compound != 0 & twitter$Resolution.type != "",], | |
FUN = median), digits = 3, col.names = c("Resolution", "Sentiment Score")) | |
# How do people’s friends feel about their resolutions? | |
library(plyr) | |
agg_twitter <- ddply(twitter[twitter$Resolution.type != "" & twitter$Compound != 0,], | |
"Resolution.type", summarise, | |
mdn.compound = median(Compound), | |
num.resolutions = length(Resolution.type), | |
prop.favourite = sum(Five.or.more.favourites) / length(Resolution.type)) | |
p3 <- ggplot(data = agg_twitter, aes(x = mdn.compound, y = prop.favourite, | |
size = num.resolutions, | |
colour = Resolution.type)) + | |
geom_point() + | |
scale_size_area(max_size = 25) + | |
ggtitle("Weighted scatterplot of tweet sentiment against number of favourites") + | |
scale_x_continuous(limits = c(0.1, 0.6), name = "Compound sentiment score (median)") + | |
scale_y_continuous(limits = c(0.14, 0.23), name = "Received five or more favourites (%)") + | |
scale_colour_brewer(palette = "Paired") + | |
labs(colour = "Resolution", size = "Number of tweets") + | |
theme_bw() + | |
theme(plot.title = element_text(size = 12, family = "Tahoma", face = "bold"), | |
text = element_text(size = 10, family = "Tahoma")) | |
p3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment