library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
library(ggplot2)
data<- read_csv("figure-data.csv")
## Rows: 221 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (7): Social Media, Twitter, Big Data, Google Trend, Facebook, Cell Phon...
## date (1): date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
dim(data)
## [1] 221 8
names(data)
## [1] "date" "Social Media" "Twitter"
## [4] "Big Data" "Google Trend" "Facebook"
## [7] "Cell Phone" "Call Detail Records"
str(data)
## spc_tbl_ [221 × 8] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ date : Date[1:221], format: "2020-01-29" "2020-01-30" ...
## $ Social Media : num [1:221] 0 0 0 0 0 0 0 0 0 0 ...
## $ Twitter : num [1:221] 0 0 0 0 0 0 0 0 0 0 ...
## $ Big Data : num [1:221] 0 0 0 0 0 0 0 0 0 0 ...
## $ Google Trend : num [1:221] 1 1 1 1 1 1 1 1 1 1 ...
## $ Facebook : num [1:221] 0 0 0 0 0 0 0 0 0 0 ...
## $ Cell Phone : num [1:221] 0 0 0 0 0 0 0 0 0 0 ...
## $ Call Detail Records: num [1:221] 0 0 0 0 0 0 0 0 0 0 ...
## - attr(*, "spec")=
## .. cols(
## .. date = col_date(format = ""),
## .. `Social Media` = col_double(),
## .. Twitter = col_double(),
## .. `Big Data` = col_double(),
## .. `Google Trend` = col_double(),
## .. Facebook = col_double(),
## .. `Cell Phone` = col_double(),
## .. `Call Detail Records` = col_double()
## .. )
## - attr(*, "problems")=<pointer: 0xb433bf400>
head(data)
## # A tibble: 6 × 8
## date `Social Media` Twitter `Big Data` `Google Trend` Facebook
## <date> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2020-01-29 0 0 0 1 0
## 2 2020-01-30 0 0 0 1 0
## 3 2020-01-31 0 0 0 1 0
## 4 2020-02-01 0 0 0 1 0
## 5 2020-02-02 0 0 0 1 0
## 6 2020-02-03 0 0 0 1 0
## # ℹ 2 more variables: `Cell Phone` <dbl>, `Call Detail Records` <dbl>
data_long <- data %>% pivot_longer( cols = -date, names_to = "source", values_to = "value")
head(data_long)
## # A tibble: 6 × 3
## date source value
## <date> <chr> <dbl>
## 1 2020-01-29 Social Media 0
## 2 2020-01-29 Twitter 0
## 3 2020-01-29 Big Data 0
## 4 2020-01-29 Google Trend 1
## 5 2020-01-29 Facebook 0
## 6 2020-01-29 Cell Phone 0
source_summary <- data_long %>% group_by(source) %>% summarize( average_activity = mean(value, na.rm = TRUE))
source_summary
## # A tibble: 7 × 2
## source average_activity
## <chr> <dbl>
## 1 Big Data 54.9
## 2 Call Detail Records 2.19
## 3 Cell Phone 8.51
## 4 Facebook 28.0
## 5 Google Trend 31.3
## 6 Social Media 207.
## 7 Twitter 86.2
source_count <- data_long %>% count(source)
source_count
## # A tibble: 7 × 2
## source n
## <chr> <int>
## 1 Big Data 221
## 2 Call Detail Records 221
## 3 Cell Phone 221
## 4 Facebook 221
## 5 Google Trend 221
## 6 Social Media 221
## 7 Twitter 221
daily_activity <- data_long %>% group_by(date, source) %>% summarize( daily_activity = mean(value, na.rm = TRUE), .groups = "drop")
head(daily_activity)
## # A tibble: 6 × 3
## date source daily_activity
## <date> <chr> <dbl>
## 1 2020-01-29 Big Data 0
## 2 2020-01-29 Call Detail Records 0
## 3 2020-01-29 Cell Phone 0
## 4 2020-01-29 Facebook 0
## 5 2020-01-29 Google Trend 1
## 6 2020-01-29 Social Media 0
ggplot(daily_activity, aes(x = date, y = daily_activity, color = source)) + geom_line() + labs( title = "Activity Across Data Sources Over Time", x = "Date", y = "Activity Level", color = "Data Source" ) + theme_minimal()
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
Social Media had the highest average activity during the study period with Call Detail having the lowest average activity during the same period.