Collecting, Analyzing and Presenting data about the participation in #ilovefs day
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plotte.R 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. ################################################################################
  2. # plotte.R #
  3. # Plotting scraped data for "I Love Free Software Day" #
  4. # Jan Weymeirsch janwey@fsfe.org #
  5. ################################################################################
  6. ## Loading Packages {{{ ----
  7. install.packages("stringi")
  8. library("stringi")
  9. # }}}
  10. ## Loading Data {{{ ----
  11. load(file = "./data/ilovefs-all_2018-02-15_16-21-06.RData")
  12. ### following requires you to extract the hashtags first (see further down).
  13. ### this can later be imported via a CSV file again
  14. hashtags <- read.csv2(file = "./data/ilovefs-projects_manual.csv", header = TRUE, sep = ",")
  15. # }}}
  16. ## Extract Hashtags {{{ ----
  17. ### Fediverse
  18. mastodon_hashtags_l <- stri_extract_all(str = mastodon$text, regex = "#\\w+")
  19. mastodon_hashtags <- c()
  20. for(i in c(1:length(mastodon_hashtags_l))){
  21. for(j in c(1:length(mastodon_hashtags_l[[i]]))){
  22. mastodon_hashtags <- c(mastodon_hashtags, mastodon_hashtags_l[[i]][j])
  23. }
  24. }
  25. mastodon_hashtags <- sub(x = mastodon_hashtags, pattern = ",", replace = "")
  26. mastodon_hashtags <- sub(x = mastodon_hashtags, pattern = "\\:", replace = "")
  27. mastodon_hashtags <- sub(x = mastodon_hashtags, pattern = "\\?", replace = "")
  28. mastodon_hashtags <- sub(x = mastodon_hashtags, pattern = "\\!", replace = "")
  29. mastodon_hashtags <- sub(x = mastodon_hashtags, pattern = "…", replace = "")
  30. unique(mastodon_hashtags)
  31. ### Twitter
  32. twitter_hashtags_l <- stri_extract_all(str = twitter$text, regex = "#\\w+")
  33. twitter_hashtags <- c()
  34. for(i in c(1:length(twitter_hashtags_l))){
  35. for(j in c(1:length(twitter_hashtags_l[[i]]))){
  36. twitter_hashtags <- c(twitter_hashtags, twitter_hashtags_l[[i]][j])
  37. }
  38. }
  39. twitter_hashtags <- sub(x = twitter_hashtags, pattern = ",", replace = "")
  40. twitter_hashtags <- sub(x = twitter_hashtags, pattern = "\\:", replace = "")
  41. twitter_hashtags <- sub(x = twitter_hashtags, pattern = "\\?", replace = "")
  42. twitter_hashtags <- sub(x = twitter_hashtags, pattern = "\\!", replace = "")
  43. twitter_hashtags <- sub(x = twitter_hashtags, pattern = "…", replace = "")
  44. unique(twitter_hashtags)
  45. # }}}
  46. ## Extract Mentions {{{ ----
  47. ### Fediverse
  48. mastodon_mentions_l <- stri_extract_all(str = mastodon$text, regex = "\\@\\S+")
  49. mastodon_mentions <- c()
  50. for(i in c(1:length(mastodon_mentions_l))){
  51. for(j in c(1:length(mastodon_mentions_l[[i]]))){
  52. mastodon_mentions <- c(mastodon_mentions, mastodon_mentions_l[[i]][j])
  53. }
  54. }
  55. mastodon_mentions <- sub(x = mastodon_mentions, pattern = ",", replace = "")
  56. mastodon_mentions <- sub(x = mastodon_mentions, pattern = "\\:", replace = "")
  57. mastodon_mentions <- sub(x = mastodon_mentions, pattern = "\\?", replace = "")
  58. mastodon_mentions <- sub(x = mastodon_mentions, pattern = "\\!", replace = "")
  59. mastodon_mentions <- sub(x = mastodon_mentions, pattern = "…", replace = "")
  60. unique(mastodon_mentions)
  61. ### Twitter
  62. twitter_mentions_l <- stri_extract_all(str = twitter$text, regex = "\\@\\S+")
  63. twitter_mentions <- c()
  64. for(i in c(1:length(twitter_mentions_l))){
  65. for(j in c(1:length(twitter_mentions_l[[i]]))){
  66. twitter_mentions <- c(twitter_mentions, twitter_mentions_l[[i]][j])
  67. }
  68. }
  69. twitter_mentions <- sub(x = twitter_mentions, pattern = ",", replace = "")
  70. twitter_mentions <- sub(x = twitter_mentions, pattern = "\\:", replace = "")
  71. twitter_mentions <- sub(x = twitter_mentions, pattern = "\\?", replace = "")
  72. twitter_mentions <- sub(x = twitter_mentions, pattern = "\\!", replace = "")
  73. twitter_mentions <- sub(x = twitter_mentions, pattern = "…", replace = "")
  74. unique(twitter_mentions)
  75. # }}}
  76. ### Participation per Platform {{{ ----
  77. #### Calculating Platform numbers
  78. ##### Platform (Twitter/Fediverse)
  79. twitter_number <- rep(x = "twitter", times = length(twitter$text))
  80. fediver_number <- rep(x = "fediverse", times = length(mastodon$text))
  81. platform <- factor(c(twitter_number, fediver_number), levels = c("fediverse", "twitter"))
  82. ##### Instances (Fediverse)
  83. msoc <- grep(x = as.character(mastodon$acct), pattern = "@", invert = TRUE)
  84. instances <- sub(x = as.character(mastodon$acct), pattern = ".*\\@", replace = "")
  85. instances[msoc] <- "mastodon.social"
  86. instances <- as.factor(instances)
  87. #### Plotting the results
  88. pdf(file = "./plots/participation_platform.pdf", height = 8.75, width = 17.5)
  89. par(mfrow = c(1,2))
  90. ##### Platform (Twitter/Fediverse)
  91. plot(x = platform,
  92. col = c("#a22430", "#1da1f2"),
  93. ylim = c(0, ceiling(max(table(platform))/100) * 100),
  94. main = "#ilovefs participation by Platform",
  95. names.arg = c("The Fediverse", "Twitter"))
  96. ##### Instances (Fediverse)
  97. plot(x = instances,
  98. horiz = FALSE,
  99. col = rainbow(n = length(unique(instances))),
  100. ylim = c(0, ceiling(max(table(instances))/10) * 10),
  101. main = "#ilovefs participation by Instance",
  102. names.arg = "")
  103. legend(x = "topleft", legend = levels(instances),
  104. fill = rainbow(n = length(unique(instances))),
  105. bty = "n", ncol = 2)
  106. dev.off()
  107. # }}}
  108. ### Time and Date {{{ ----
  109. #### Aggregate Date & Time into single strings
  110. twitter_datetime <- rev(paste0(twitter$date, twitter$time))
  111. fediver_datetime <- rev(paste0(mastodon$date, mastodon$time))
  112. #### Density Plots of Postings over Time
  113. pdf(file = "./plots/participation_datetime.pdf", height = 7, width = 7)
  114. ##### Fediverse (initial plot)
  115. plot(density(as.numeric(fediver_datetime)),
  116. type = "h", xaxt = "n", yaxt = "n",
  117. xlab = "Time", ylab = "Number of Posts",
  118. main = "Participation around I Love Free Software Day",
  119. col = "#a22430", axes = FALSE, lwd = 1)
  120. ##### Twitter
  121. lines(density(as.numeric(twitter_datetime)), type = "h", col = "#1da1f2", lwd = 1)
  122. ##### Added Axis (shows date)
  123. axis(side = 1, labels = c("10.02.18", "11.02.18", "12.02.18", "13.02.18", "14.02.18", "15.02.18"),
  124. at = c(20180210120000, 20180211120000, 20180212120000, 20180213120000, 20180214120000, 20180215120000))
  125. ##### Add legend
  126. legend(x = "topleft", legend = c("Twitter", "Fediverse"),
  127. fill = c("#1da1f2", "#a22430"), bty = "n")
  128. dev.off()
  129. #### Extract posting times only on February 14th
  130. twitter_ilfsd <- twitter$time[which(twitter$date == "20180214")]
  131. fediver_ilfsd <- mastodon$time[which(mastodon$date == "20180214")]
  132. #### Get aggregated number of posts over time during the day
  133. time <- seq(from = 000000, to = 240000, by = 010000)
  134. twitter_aggregated <- c()
  135. for(i in 1:length(time)){
  136. twitter_aggregated[i] <- length(which(as.numeric(rev(twitter_ilfsd)) < time[i]))
  137. }
  138. fediver_aggregated <- c()
  139. for(i in 1:length(time)){
  140. fediver_aggregated[i] <- length(which(as.numeric(rev(fediver_ilfsd)) < time[i]))
  141. }
  142. #### Plotting the aggregated number of posts during the day
  143. pdf(file = "./plots/participation_time.pdf", height = 7, width = 7)
  144. ##### Twitter
  145. plot(x = time, y = twitter_aggregated, type = "l",
  146. main = "Number of Posts about #ilovefs on February 14 2018",
  147. xlab = "",
  148. ylab = "Number of Posts",
  149. xaxt = "n", col = "#1da1f2", lwd = 5,
  150. axes = FALSE)
  151. ##### Fediverse
  152. lines(x = time, y = fediver_aggregated, type = "l", col = "#a22430", lwd = 5)
  153. ##### Add Axis (show time and number of posts)
  154. axis(side = 1, labels = c("00:00", "03:00", "06:00", "09:00", "12:00", "15:00", "18:00", "21:00", "24:00"),
  155. at = c(000000, 030000, 060000, 090000, 120000, 150000, 180000, 210000, 240000))
  156. axis(side = 2, labels = as.character(seq(from = 0, to = max(twitter_aggregated), by = 50)),
  157. at = seq(from = 0, to = max(twitter_aggregated), by = 50))
  158. ##### Add legend
  159. legend(x = "topleft", legend = c("Twitter", "Fediverse"),
  160. fill = c("#1da1f2", "#a22430"), bty = "n")
  161. dev.off()
  162. # }}}