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 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. ################################################################################
  2. # Copyright (c) 2018 Free Software Foundation Europe e.V. <contact@fsfe.org>
  3. # Author 2018 Jan Weymeirsch <janwey@fsfe.org>
  4. # SPDX-License-Identifier: GPL-3.0
  5. ################################################################################
  6. ## Loading Packages {{{ ----
  7. ### ggplot2 for plots
  8. if(!require("ggplot2")){ install.packages("ggplot2"); library("ggplot2") }
  9. ### arrange ggplot2 plots
  10. if(!require("gridExtra")){ install.packages("gridExtra"); library("gridExtra") }
  11. # }}}
  12. ## Loading Data {{{ ----
  13. load(file = "./data/ilovefs-all_2018-02-20_14-57-16.RData")
  14. ### following requires you to extract the hashtags first (see further down).
  15. ### this can later be imported via a CSV file again
  16. hash_ment <- read.csv2(file = "./data/tags_mentions.csv", sep = ",", header = FALSE)
  17. # }}}
  18. ## Extract Hashtags {{{ ----
  19. ### Fediverse
  20. mastodon_hashtags_l <- stri_extract_all(str = mastodon$text, regex = "#\\w+")
  21. mastodon_hashtags <- c()
  22. for(i in c(1:length(mastodon_hashtags_l))){
  23. for(j in c(1:length(mastodon_hashtags_l[[i]]))){
  24. mastodon_hashtags <- c(mastodon_hashtags, mastodon_hashtags_l[[i]][j])
  25. }
  26. }
  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. mastodon_hashtags <- sub(x = mastodon_hashtags, pattern = "\\!", replace = "")
  31. mastodon_hashtags <- sub(x = mastodon_hashtags, pattern = "…", replace = "")
  32. unique(mastodon_hashtags)
  33. ### Twitter
  34. twitter_hashtags_l <- stri_extract_all(str = twitter$text, regex = "#\\w+")
  35. twitter_hashtags <- c()
  36. for(i in c(1:length(twitter_hashtags_l))){
  37. for(j in c(1:length(twitter_hashtags_l[[i]]))){
  38. twitter_hashtags <- c(twitter_hashtags, twitter_hashtags_l[[i]][j])
  39. }
  40. }
  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. twitter_hashtags <- sub(x = twitter_hashtags, pattern = "\\!", replace = "")
  45. twitter_hashtags <- sub(x = twitter_hashtags, pattern = "…", replace = "")
  46. unique(twitter_hashtags)
  47. # }}}
  48. ## Extract Mentions {{{ ----
  49. ### Fediverse
  50. mastodon_mentions_l <- stri_extract_all(str = mastodon$text, regex = "\\@\\S+")
  51. mastodon_mentions <- c()
  52. for(i in c(1:length(mastodon_mentions_l))){
  53. for(j in c(1:length(mastodon_mentions_l[[i]]))){
  54. mastodon_mentions <- c(mastodon_mentions, mastodon_mentions_l[[i]][j])
  55. }
  56. }
  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. mastodon_mentions <- sub(x = mastodon_mentions, pattern = "\\!", replace = "")
  61. mastodon_mentions <- sub(x = mastodon_mentions, pattern = "…", replace = "")
  62. unique(mastodon_mentions)
  63. ### Twitter
  64. twitter_mentions_l <- stri_extract_all(str = twitter$text, regex = "\\@\\S+")
  65. twitter_mentions <- c()
  66. for(i in c(1:length(twitter_mentions_l))){
  67. for(j in c(1:length(twitter_mentions_l[[i]]))){
  68. twitter_mentions <- c(twitter_mentions, twitter_mentions_l[[i]][j])
  69. }
  70. }
  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. twitter_mentions <- sub(x = twitter_mentions, pattern = "\\!", replace = "")
  75. twitter_mentions <- sub(x = twitter_mentions, pattern = "…", replace = "")
  76. unique(twitter_mentions)
  77. # }}}
  78. ### Participation per Platform {{{ ----
  79. #### Calculating Platform numbers
  80. ##### Platform (Twitter/Fediverse)
  81. twitter_number <- rep(x = "twitter", times = length(twitter$text))
  82. fediver_number <- rep(x = "fediverse", times = length(mastodon$text))
  83. platform <- factor(c(twitter_number, fediver_number), levels = c("fediverse", "twitter"))
  84. ##### Instances (Fediverse)
  85. msoc <- grep(x = as.character(mastodon$acct), pattern = "@", invert = TRUE)
  86. instances <- sub(x = as.character(mastodon$acct), pattern = ".*\\@", replace = "")
  87. instances[msoc] <- "mastodon.social"
  88. instances <- as.factor(instances)
  89. #### Plotting the results
  90. pdf(file = "./plots/participation_platform.pdf", height = 10, width = 20)
  91. par(mfrow = c(1,2))
  92. ##### Platform (Twitter/Fediverse)
  93. plot(x = platform,
  94. col = c("#a22430", "#1da1f2"),
  95. ylim = c(0, ceiling(max(table(platform))/100) * 100),
  96. main = "#ilovefs participation by Platform",
  97. names.arg = c("The Fediverse", "Twitter"))
  98. ##### Instances (Fediverse)
  99. plot(x = instances,
  100. horiz = FALSE,
  101. col = rainbow(n = length(unique(instances))),
  102. ylim = c(0, ceiling(max(table(instances))/10) * 10),
  103. main = "#ilovefs participation by Instance",
  104. names.arg = "")
  105. legend(x = "topleft", legend = levels(instances),
  106. fill = rainbow(n = length(unique(instances))),
  107. bty = "n", ncol = 2)
  108. dev.off()
  109. # }}}
  110. ### Time and Date {{{ ----
  111. #### Transform time into POSIX dates
  112. twitter_time <- strptime(paste0(twitter$date, twitter$time),
  113. format = "%Y%m%d%H%M%S")
  114. mastodon_time <- strptime(paste0(mastodon$date, mastodon$time),
  115. format = "%Y%m%d%H%M%S")
  116. #### Participation by Time on Twitter
  117. twitter_plot <- ggplot(data = twitter, aes(x=twitter_time)) +
  118. geom_histogram(aes(fill=..count..), binwidth=60*180) +
  119. scale_x_datetime("Date") +
  120. scale_y_continuous("Frequency") +
  121. ggtitle("Participation on Twitter") +
  122. scale_fill_gradient("Count", low="#002864", high="#329cc3")
  123. #### Participation by Time in the Fediverse
  124. mastodon_plot <- ggplot(data = mastodon, aes(x=mastodon_time)) +
  125. geom_histogram(aes(fill=..count..), binwidth=60*180) +
  126. scale_x_datetime("Date") +
  127. scale_y_continuous("Frequency") +
  128. ggtitle("Participation in the Fediverse") +
  129. scale_fill_gradient("Count", low="#640000", high="#FF0000")
  130. #### Export / Save plots as PDF
  131. pdf(file="./plots/ilfs-participation-by-date.pdf", width=14, height=7)
  132. grid.arrange(twitter_plot, mastodon_plot, ncol = 2)
  133. dev.off()
  134. # }}}