rm(list=ls())
library(ggplot2)
library(grid)
library(gridExtra)
library(data.table)


setwd('~/research/gTiger/Article_citsci/open_code')
source('settings/parameters.r')
source('settings/paths.r')
source('settings/functions.r')

setwd(path_to_data)


mtable = readRDS('user_withdrawal_rates.Rds')


ptimes = readRDS('user_participation_times.Rds')

median(ptimes$total_participation_days)
mean(ptimes$total_participation_days)
quantile(ptimes$total_participation_days)

ggplot(data=ptimes, aes(x=total_participation_weeks)) + geom_histogram(bins=50) + xlab("Participation time (weeks)") + ylab("Count") + geom_line(data=mtable, aes(x=week, y=rate*3000), colour="#ef8a62", lwd=1) +  scale_y_continuous(sec.axis = sec_axis(~./3000, name = "Withdrawal rate")) 
ggsave(paste0(path_to_figures, 'withdrawal_rates_ptimes.png'), width=7, height=6, dpi=1000)
ggsave(paste0(path_to_figures, 'withdrawal_rates_ptimes.pdf'), width=7, height=6)
ggsave(paste0(path_to_figures, 'withdrawal_rates_ptimes.eps'), device="eps", width=8.27, units="in")
