Created
October 30, 2018 08:14
-
-
Save simecek/e38d12db2e88c46c4752103260f95dcf 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
| # Likes per tweet plot | |
| # Analyze user's data downloaded from Twitter | |
| library(jsonlite) | |
| library(tidyverse) | |
| # download your data from Twitter (Settings and Privacy, Your Twitter data), unzip the folder | |
| setwd("~/Downloads/twitter-2018-10-29-6c18f5c0ab3605451f73cd0fd9ed186a2fd5b2caf1812ab747d42351da805656/") | |
| json <- readLines("tweet.js") | |
| json[[1]] <- "[ {" # remove illegal window.YTD.tweet.part0 = | |
| tweets <- fromJSON(json) | |
| names(tweets) | |
| # parsing time | |
| parse_date <- function(x) { | |
| mdy_hms <- paste( | |
| substr(x, 5,10), | |
| substr(x, 27,30), | |
| substr(x, 12,19), | |
| sep = " ") | |
| as.character(lubridate::mdy_hms(mdy_hms)) | |
| } | |
| tweets$Time <- as.POSIXct(sapply(tweets$created_at, parse_date)) | |
| tweets$Likes <- as.numeric(tweets$favorite_count) | |
| tweets$Retweets <- as.numeric(tweets$retweet_count) | |
| tweets %>% | |
| select(Time, Likes, Retweets, in_reply_to_status_id) %>% | |
| filter(is.na(in_reply_to_status_id)) %>% | |
| ggplot(aes(x = Time, y = Likes)) + | |
| geom_point(alpha=0.9, color = "grey") + | |
| geom_smooth(color = "red", fill = "pink", size = 2) + | |
| theme_minimal() + | |
| ylim(-1,30) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment