Last active
August 29, 2015 14:19
-
-
Save josefslerka/6b2f6bd591b71e1c3ed6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# https://developers.facebook.com/tools/explorer/ | |
install.packages("vioplot") | |
install.packages("plyr") | |
library(plyr) | |
library(vioplot) | |
library(Rfacebook) | |
library(xlsx) | |
token <- "CAACEdEose0cBAIdf3CeSo9jb5R6ksiZC4Ez4CtyBV1JgkRRHjEGZCt9gc1rKl7tqYsUOyMOXvaXAJqZBU86GWGSkBWomre0NnvAMAKdkCLU1nZBb3wEV6ZBHZBvDddgOUVXVTtmIqGlrrinY1F2MXZAOOApIfyDQ31WNz4R4UMnQeP9cCHT2ZAvQZCeypbsEsu0cMDvwX00ugfbF1HQFOwdXpZCljmdc3CpZC0ZD" | |
x = 300 | |
name <- "hnutiusvit.cz" | |
page <- getPage(name, token, n = x) | |
write.csv(page, "hnutiusvit.cz.csv") | |
filename <- paste0(name, ".xls", sep="") | |
write.xlsx(page, filename, sheetName=name) | |
# druhy | |
page$likes_count_cat <- cut(page$likes_count, | |
breaks=c(-Inf, quantile(page$likes_count, .20), quantile(page$likes_count, .80), Inf), labels=c("low", "normal", "high")) | |
page$comments_count_cat <- cut(page$comments_count, | |
breaks=c(-Inf, quantile(page$comments_count, .20), quantile(page$comments_count, .80), Inf), | |
labels=c("low", "normal", "high")) | |
cases <- data.frame(page$type, page$likes_count_cat, page$comments_count_cat) | |
pravidla <- apriori(cases, | |
parameter=list(support=0.02, confidence=0.05), | |
appearance = list(rhs=c("page.likes_count_cat=high"), | |
default="lhs"), | |
control = list(verbose=F)) | |
pravidla.sorted <- sort(pravidla, by="lift") | |
inspect(pravidla.sorted) | |
subset.matrix <- is.subset(pravidla.sorted, pravidla.sorted) | |
subset.matrix[lower.tri(subset.matrix, diag=T)] <- NA | |
redundant <- colSums(subset.matrix, na.rm=T) >= 1 | |
# remove redundant rules | |
rules.pruned <- pravidla.sorted[!redundant] | |
inspect(rules.pruned) | |
# zjsiteni typu | |
class(page) | |
# vypis ukazky | |
head(page$type) | |
# zakladni stats | |
summary(page$likes_count) | |
# histogram | |
hist(page$likes_count) | |
# boxplot | |
boxplot(page$likes_count) | |
boxplot(page$likes_count, outline=FALSE) | |
boxplot(page$likes_count, page$comments_count, outline=FALSE) | |
boxplot(page$likes_count, page$comments_count, page$shares_count, names=c("likes","comments","shares"), outline=FALSE) | |
table(page$type) | |
pie(druhy) | |
vioplot(page$likes_count, page$comments_count, page$shares_count, names=c("likes","comments","shares")) | |
plot(page$likes_count, page$comments_count) | |
plot(page$likes_count, page$comments_count, xlab="pocet likes", ylab="pocet komentaru", main="HNUTI") | |
postPage <- subset(page, type=="link") | |
page$type[page$likes_count > 200] | |
quantile(page$likes_count,.95) | |
table(page$type[page$likes_count>85]) | |
page$time <- format(as.POSIXlt(page$created_time)) | |
likes_by_day <- aggregate(likes_count ~ time, page, sum) | |
colnames(likes_by_day) <- c("date", "sum") | |
likes_by_day$date <- as.Date(likes_by_day$date) | |
page$months <- as.numeric(format(as.POSIXlt(page$time), format = "%y%m")) | |
likes_by_date_months <- aggregate(likes_count ~ months + time, page, sum) | |
boxplot(likes_by_date_months$likes_count ~ likes_by_date_months$months, outline=FALSE, main="Dynamika like na Hnuti Usvit") | |
plot(as.Date(likes_by_day$time),likes_by_day$likes_count) | |
plot(as.Date(likes_by_day$time),likes_by_day$likes_count, type="h") | |
plot(as.Date(likes_by_day$time),likes_by_day$likes_count, type="h", xlab="datum", ylab="pocet likes", main="Sramkova Sobotka") | |
par(mfrow=c(1,2)) | |
plot(as.Date(likes_by_day$time),likes_by_day$likes_count, type="h", xlab="datum", ylab="pocet likes", main="Sramkova Sobotka") | |
boxplot(likes_by_date_months$likes_count ~ likes_by_date_months$months, outline=FALSE, main="Dynamika like na Sramkova Sobotka") | |
png(filename="obrazek.png", width=800, height=600) | |
boxplot(likes_by_date_months$likes_count ~ likes_by_date_months$months, outline=FALSE, main="Dynamika like na Sramkova Sobotka") | |
dev.off() | |
datum <- data.frame(seq(from = as.Date("2014-09-30"), to = as.Date("2015-03-01"), by = 1)) | |
colnames(datum) <- c("date") | |
sjednocena <- join(datum, likes_by_day, type="left") | |
barplot(sjednocena$sum) | |
# http://thinktostart.com/cluster-twitter-data-with-r-and-k-means/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment