-
Notifications
You must be signed in to change notification settings - Fork 1
/
createPlots.R
106 lines (89 loc) · 3.47 KB
/
createPlots.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
library(ggplot2)
library(ggthemes)
library(reshape2)
# get base directory and file handles
args = commandArgs(trailingOnly=TRUE)
base_dir = args[1]
genotype_file = paste(base_dir,"number_genotypes.csv", sep = "/")
user_file = paste(base_dir,"number_users.csv", sep = "/")
phenotype_file = paste(base_dir,"number_phenotypes.csv", sep = "/")
user_phenotype_file = paste(base_dir,"number_user_phenotypes.csv", sep = "/")
# read all files in & fix date format
genotype <- read.csv(file=genotype_file,sep="\t",head=F)
genotype$date <- as.POSIXct(as.character(genotype$V2),format="%d.%m.%Y")
user <- read.csv(file=user_file,sep="\t",head=F)
user$date <- as.POSIXct(as.character(user$V2),format="%d.%m.%Y")
phenotype <- read.csv(file=phenotype_file,sep="\t",head=F)
phenotype$date <- as.POSIXct(as.character(phenotype$V2),format="%d.%m.%Y")
user_phenotype <- read.csv(file=user_phenotype_file,sep="\t",head=F)
user_phenotype$date <- as.POSIXct(as.character(user_phenotype$V2),format="%d.%m.%Y")
# do single plots for each
# genotype
ggplot(genotype,aes(date,V1)) +
geom_smooth() +
theme_light() +
scale_x_datetime("Date") +
scale_y_continuous("# of Genotypes")
ggsave(paste(base_dir,"genotypes.png",sep="/"),width=4, height=3, dpi=100)
# users
ggplot(user,aes(date,V1)) +
geom_smooth() +
theme_light() +
scale_x_datetime("Date") +
scale_y_continuous("# of Users")
ggsave(paste(base_dir,"users.png",sep="/"),width=4, height=3, dpi=100)
# users
ggplot(phenotype,aes(date,V1)) +
geom_smooth() +
theme_light() +
scale_x_datetime("Date") +
scale_y_continuous("# of Phenotypes")
ggsave(paste(base_dir,"phenotypes.png",sep="/"),width=4, height=3, dpi=100)
# user phenotypes
ggplot(user_phenotype,aes(date,V1)) +
geom_smooth() +
theme_light() +
scale_x_datetime("Date") +
scale_y_continuous("# of Phenotype Answers")
ggsave(paste(base_dir,"user_phenotypes.png",sep="/"),width=4, height=3, dpi=100)
# now let's do merged graphs of user & genotypes and phenotype/user phenotypes
# users & genotypes
# nicer column labels
user$users <- user$V1
genotype$genotypes <- genotype$V1
# merge DFs and drop useless columns
geno_user_merge <- merge(user,genotype,by="date")
geno_user_merge$V1.x <- NULL
geno_user_merge$V1.y <- NULL
geno_user_merge$V2.y <- NULL
geno_user_merge$V2.x <- NULL
# convert from wide to long
geno_user_merge_long <- melt(geno_user_merge, id.vars="date",variable.name="category")
# plot graphs
ggplot(geno_user_merge_long,aes(date,value,color=category)) +
geom_smooth() +
scale_color_discrete("Category") +
scale_x_datetime("Date") +
scale_y_continuous("total #") +
theme_minimal()
ggsave(paste(base_dir,"geno_plus_phenotypes.png",sep="/"),width=4, height=3, dpi=100)
# now we do phenotypes & user phenotypes
# nicer column labels
phenotype$phenotypes <- phenotype$V1
user_phenotype$phenotype_answers <- user_phenotype$V1
# merge DFs and drop useless columns
pheno_userpheno_merge <- merge(user_phenotype,phenotype,by="date")
pheno_userpheno_merge$V1.x <- NULL
pheno_userpheno_merge$V1.y <- NULL
pheno_userpheno_merge$V2.y <- NULL
pheno_userpheno_merge$V2.x <- NULL
# convert from wide to long
pheno_userpheno_merge_long <- melt(pheno_userpheno_merge, id.vars="date",variable.name="category")
# plot graphs
ggplot(pheno_userpheno_merge_long,aes(date,value,color=category)) +
geom_smooth() +
scale_color_discrete("Category") +
scale_x_datetime("Date") +
scale_y_continuous("total #") +
theme_minimal()
ggsave(paste(base_dir,"pheno_plus_userpheno.png",sep="/"),width=4, height=3, dpi=100)