-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.SetupScript.R
248 lines (194 loc) · 10.3 KB
/
1.SetupScript.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#Startup
# Packages
require(ggplot2)
require(reshape)
require(knitr)
require(xts)
# Functions
myfacettheme <- theme_grey() +
theme(text=element_text(size=12),
axis.ticks = element_line(colour = "black"),
axis.text = element_text(size=12),
axis.title.y = element_text(angle=90, vjust=1),
axis.text.x = element_text(size=11, angle=90, hjust=1,vjust=0.5),
legend.key = element_blank(),
legend.text = element_text(size=12),
legend.title = element_text(size=14),
panel.background = element_rect(fill="white", colour=NA),
panel.border = element_rect(fill = NA, colour = "grey50"),
panel.grid.major = element_blank(),
panel.grid.minor = element_line(colour="grey98", size=0.5),
strip.background = element_rect(fill="grey80", colour="grey50"),
strip.text.x= element_text(size=11)
)
namean <- function(x) {mean(x, na.rm=T)}
nasd <- function(x) {sd(x, na.rm=T)}
F.hierarcplot <- function(dat,
col1L = 0,
col2L = 0.1,
col3L = 0.2,
col4L = 0.35,
col5L = 0.6,
col5R = 1,
wrapsize1=9,
wrapsize2=12,
wrapsize3=15,
wrapsize4=35,
wrapsize5=45,
fontsize1=1,
fontsize2=1,
fontsize3=1,
fontsize4=0.75,
fontsize5=0.5,
domcol="DomainColour",
thmcol="DomainColour",
cluscol="white",
projcol="ProximityColour",
detcol="StatusColour",
numcols=5,
statustoinclude=c("STALLED", "COMPLETE", "ABANDONED", "IDEA", "ACTIVE", "MERGED"))
{
# dat is a data frame containing the hierarchically-organized information.
# column coordinates are set based on expected content. Default values are what last worked for mine.
# note this function is written for 4 or 5 columns and isn't flexible to other options.
### Subset for status I care about
dat <- dat[dat$projectSTATUS %in% statustoinclude,]
#PROJECT COLUMN
# determine number of rows and sizes for project column
projcoor <- data.frame(L=rep(col4L, times=nrow(dat)),
R=rep(col5L, times=nrow(dat)),
B=rep(NA, times=nrow(dat)),
T=rep(NA, times=nrow(dat)))
for (i in 1:nrow(projcoor)) {
projcoor[i,3] <- 1 - (i / nrow(projcoor)) # bottom coordinate
projcoor[i,4] <- 1 - ((i-1)/nrow(projcoor)) # top coordinate
}
# determine number of rows and sizes for project detail column
detcoor <- data.frame(L=rep(col5L, times=nrow(dat)),
R=rep(col5R, times=nrow(dat)),
B=rep(NA, times=nrow(dat)),
T=rep(NA, times=nrow(dat)))
for (i in 1:nrow(detcoor)) {
detcoor[i,3] <- 1 - (i / nrow(detcoor)) # bottom coordinate
detcoor[i,4] <- 1 - ((i-1)/nrow(detcoor)) # top coordinate
}
# determine number of rows and sizes for cluster column
uniqueclus <- length(unique(dat$clusterNAME))
cluscoor <- data.frame(L=rep(col3L, times=uniqueclus),
R=rep(col4L, times=uniqueclus),
B=rep(NA, times=uniqueclus),
T=rep(NA, times=uniqueclus))
for (i in 1:nrow(cluscoor)) {
if (i == 1) {
nproj.in.prevclus <- 0
ithclus <- unique(dat$clusterNAME)[i]
nproj.in.ithclus <- length(dat$PROJECTname[dat$clusterNAME %in% ithclus])
} else {
prevclus <- unique(dat$clusterNAME)[1:(i-1)] # clusters previously populated
nproj.in.prevclus <- length(dat$PROJECTname[dat$clusterNAME %in% prevclus]) # number of projects within previously populated clusters
ithclus <- unique(dat$clusterNAME)[i] # cluster to populate on ith iteration
nproj.in.ithclus <- length(dat$PROJECTname[dat$clusterNAME %in% ithclus]) # number of projects within this cluster
}
cluscoor[i,3] <- 1 - ((nproj.in.ithclus + nproj.in.prevclus) / nrow(dat)) # bottom coordinate
cluscoor[i,4] <- 1 - (nproj.in.prevclus/nrow(dat)) # top coordinate
}
# determine number of rows and sizes for theme column
uniquetheme <- length(unique(dat$themeNAME))
themecoor <- data.frame(L=rep(col2L, times=uniquetheme),
R=rep(col3L, times=uniquetheme),
B=rep(NA, times=uniquetheme),
T=rep(NA, times=uniquetheme))
for (i in 1:nrow(themecoor)) {
if (i == 1) {
nproj.in.prevtheme <- 0
iththeme <- unique(dat$themeNAME)[i]
nproj.in.iththeme <- length(dat$PROJECTname[dat$themeNAME %in% iththeme])
} else {
prevtheme <- unique(dat$themeNAME)[1:(i-1)] # themes previously populated
nproj.in.prevtheme <- length(dat$PROJECTname[dat$themeNAME %in% prevtheme]) # number of projects within previously populated themes
iththeme <- unique(dat$themeNAME)[i] # cluster to populate on ith iteration
nproj.in.iththeme <- length(dat$PROJECTname[dat$themeNAME %in% iththeme]) # number of projects within this theme
}
themecoor[i,3] <- 1 - ((nproj.in.iththeme + nproj.in.prevtheme) / nrow(dat)) # bottom coordinate
themecoor[i,4] <- 1 - (nproj.in.prevtheme/nrow(dat)) # top coordinate
}
# determine number of rows and sizes for domain column
uniquedomain <- length(unique(dat$domainNAME))
domaincoor <- data.frame(L=rep(col1L, times=uniquedomain),
R=rep(col2L, times=uniquedomain),
B=rep(NA, times=uniquedomain),
T=rep(NA, times=uniquedomain))
for (i in 1:nrow(domaincoor)) {
if (i == 1) {
nproj.in.prevdomain <- 0
ithdomain <- unique(dat$domainNAME)[i]
nproj.in.ithdomain <- length(dat$PROJECTname[dat$domainNAME %in% ithdomain])
} else {
prevdomain <- unique(dat$domainNAME)[1:(i-1)] # themes previously populated
nproj.in.prevdomain <- length(dat$PROJECTname[dat$domainNAME %in% prevdomain]) # number of projects within previously populated domains
ithdomain <- unique(dat$domainNAME)[i] # cluster to populate on ith iteration
nproj.in.ithdomain <- length(dat$PROJECTname[dat$domainNAME %in% ithdomain]) # number of projects within this domain
}
domaincoor[i,3] <- 1 - ((nproj.in.ithdomain + nproj.in.prevdomain) / nrow(dat)) # bottom coordinate
domaincoor[i,4] <- 1 - (nproj.in.prevdomain/nrow(dat)) # top coordinate
}
# COMBINE ALL COORDINATES INTO ONE BIG MATRIX.
if (numcols == 4) {
allcoor <- rbind(themecoor, cluscoor, projcoor, detcoor)
texttoprint <- c(as.character(dat$themeNAME[!duplicated(dat$themeNAME)]),
as.character(dat$clusterNAME[!duplicated(dat$clusterNAME)]),
as.character(dat$PROJECTname),
as.character(dat$PROJECTpurpose))
wraplength <- c(rep(wrapsize2, times=length(unique(dat$themeNAME))), #theme
rep(wrapsize3, times=length(unique(dat$clusterNAME))), #cluster
rep(wrapsize4, times=length(dat$PROJECTname)), #project
rep(wrapsize5, times=length(dat$PROJECTpurpose))) #purpose
fontsize <- c(rep(fontsize2, times=length(unique(dat$themeNAME))), #theme
rep(fontsize3, times=length(unique(dat$clusterNAME))), #cluster
rep(fontsize4, times=length(dat$PROJECTname)), #project
rep(fontsize5, times=length(dat$PROJECTpurpose))) #purpose
thmcoldf <- data.frame(Theme=dat$themeNAME, ThemeColour=dat[[thmcol]])
thmcoldf <- thmcoldf[!duplicated(thmcoldf$Theme),]
bgcolour <- c(as.character(thmcoldf$ThemeColour), #theme
rep(cluscol, times=length(unique(dat$clusterNAME))), #cluster
as.character(dat[[projcol]]), #project
as.character(dat[[detcol]])) #purpose
}
if (numcols == 5){
allcoor <- rbind(domaincoor, themecoor, cluscoor, projcoor, detcoor)
texttoprint <- c(as.character(dat$domainNAME[!duplicated(dat$domainNAME)]),
as.character(dat$themeNAME[!duplicated(dat$themeNAME)]),
as.character(dat$clusterNAME[!duplicated(dat$clusterNAME)]),
as.character(dat$PROJECTname),
as.character(dat$PROJECTpurpose))
wraplength <- c(rep(wrapsize1, times=length(unique(dat$domainNAME))), # domain
rep(wrapsize2, times=length(unique(dat$themeNAME))), #theme
rep(wrapsize3, times=length(unique(dat$clusterNAME))), #cluster
rep(wrapsize4, times=length(dat$PROJECTname)), #project
rep(wrapsize5, times=length(dat$PROJECTpurpose))) #purpose
fontsize <- c(rep(fontsize1, times=length(unique(dat$domainNAME))), # domain
rep(fontsize2, times=length(unique(dat$themeNAME))), #theme
rep(fontsize3, times=length(unique(dat$clusterNAME))), #cluster
rep(fontsize4, times=length(dat$PROJECTname)), #project
rep(fontsize5, times=length(dat$PROJECTpurpose))) #purpose
domcoldf <- data.frame(Domain=dat$domainNAME, DomainColour=dat[[domcol]])
domcoldf <- domcoldf[!duplicated(domcoldf$Domain),]
thmcoldf <- data.frame(Theme=dat$themeNAME, ThemeColour=dat[[thmcol]])
thmcoldf <- thmcoldf[!duplicated(thmcoldf$Theme),]
bgcolour <- c(as.character(domcoldf$DomainColour), #domain
as.character(thmcoldf$ThemeColour), #theme
rep(cluscol, times=length(unique(dat$clusterNAME))), #cluster
as.character(dat[[projcol]]), #project
as.character(dat[[detcol]])) #purpose
}
split.screen(as.matrix(allcoor))
for(i in 1:nrow(allcoor)) {
par(bg=bgcolour[i])
screen(i)
par(mar = c(0, 0, 0, 0))
text(.5,.5,paste(strwrap(texttoprint[i],wraplength[i]), collapse="\n"), cex=fontsize[i])
box()
par(bg="white")
}
close.screen(all.screens = TRUE)
}