-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircularBrianne.R
More file actions
369 lines (321 loc) · 18.1 KB
/
Copy pathcircularBrianne.R
File metadata and controls
369 lines (321 loc) · 18.1 KB
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
library("circular")
library("knitr")
library("readxl")
library("ggplot2")
library("shiny")
circularData1 <- read_excel("Circcular Plot Data Corrected Acrophases May 9 2025.xlsx", sheet = "Collection 1")
circularData2 <- read_excel("Circcular Plot Data Corrected Acrophases May 9 2025.xlsx", sheet = "Collection 2")
circularData3 <- read_excel("Circcular Plot Data Corrected Acrophases May 9 2025.xlsx", sheet = "Collection 1 and 2 combined")
################################################################################
hour_labels <- c("0", "3", "6", "9", "12", "15", "18", "21")
hour_pos <- as.numeric(hour_labels)
# Adjust angles for clock24 template (clockwise, 0 at top)
label_angles <- (0.5 * pi - (hour_pos / 24) * 2 * pi) %% (2 * pi)
# Compute coordinates for labels
x_pos <- 0.8 * cos(label_angles)
y_pos <- 0.8 * sin(label_angles)
#################################amt6###########################################
amt6_1 <- circularData1[1]
amt6_1.circ <- circular(amt6_1, units = "hours", template = "clock24")
amt6_1.circ.mean <- mean(amt6_1.circ, na.rm = T)
amt6_1.circ.var <- var(amt6_1.circ, na.rm = T)
plot1 <- plot.circular(amt6_1.circ, col = "blue", cex = 0.72, pch = 16,
stack = TRUE, axes = FALSE, start.sep = 0.05, sep = 0.07,
bins = 72, ticks = FALSE, tcl = 0.05, tol = 0.77, units = "hours",
template = "clock24", rotation = "clock", zero = 0, lwd = 1,
control.circle = circle.control(lwd = 2.5, cex = 2), shrink = 0.7)
title("aMT6s", line = -0.5)
arrows.circular(amt6_1.circ.mean, length = 0.1, lwd = 2, col = "blue", shrink = 0.65)
################################################################################
# Add labels to the circular plot
text(x_pos, y_pos, labels = hour_labels, cex = 0.8)
#################################saliva cort###########################################
salvCort_1 <- circularData1[2]
salvCort_1.circ <- circular(salvCort_1, units = "hours", template = "clock24")
salvCort_1.circ.mean <- mean(salvCort_1.circ, na.rm = T)
salvCort_1.circ.var <- var(salvCort_1.circ, na.rm = T)
plot2 <- plot.circular(salvCort_1.circ, col = "red", cex = 0.72, pch = 16,
stack = TRUE, axes = FALSE, start.sep = 0.05, sep = 0.07,
bins = 72, ticks = FALSE, tcl = 0.05, tol = 0.77, units = "hours",
template = "clock24", rotation = "clock", zero = 0, lwd = 1,
control.circle = circle.control(lwd = 2.5, cex = 0.5), shrink = 0.7)
title("Salivary Cortisol", line = -0.5)
arrows.circular(salvCort_1.circ.mean, length = 0.1, lwd = 2, col = "red", shrink = 0.65)
################################################################################
# Add labels to the circular plot
text(x_pos, y_pos, labels = hour_labels, cex = 0.8)
#################################Urin cort###########################################
urnCort_1 <- circularData1[[3]]
urnCort_1.circ <- circular(urnCort_1, units = "hours", template = "clock24")
urnCort_1.circ.mean <- mean(urnCort_1.circ, na.rm = T)
urnCort_1.circ.var <- var(urnCort_1.circ, na.rm = T)
plot3 <- plot.circular(urnCort_1.circ, col = "orange", cex = 0.72, pch = 16,
stack = TRUE, axes = FALSE, start.sep = 0.05, sep = 0.07,
bins = 72, ticks = FALSE, tcl = 0.05, tol = 0.77, units = "hours",
template = "clock24", rotation = "clock", zero = 0, lwd = 1,
control.circle = circle.control(lwd = 2.5, cex = 0.5), shrink = 0.7)
title("Urinary Cortisol", line = - 0.5)
arrows.circular(urnCort_1.circ.mean, length = 0.1, lwd = 2, col = "orange", shrink = 0.65)
################################################################################
# Add labels to the circular plot
text(x_pos, y_pos, labels = hour_labels, cex = 0.8)
#################################Total Cholesterol###########################################
totChol_1 <- circularData1[4]
totChol_1.circ <- circular(totChol_1, units = "hours", template = "clock24")
totChol_1.circ.mean <- mean(totChol_1.circ, na.rm = T)
totChol_1.circ.var <- var(totChol_1.circ, na.rm = T)
plot4 <- plot.circular(totChol_1.circ, col = "green", cex = 0.72, pch = 16,
stack = TRUE, axes = FALSE, start.sep = 0.05, sep = 0.07,
bins = 72, ticks = FALSE, tcl = 0.05, tol = 0.77, units = "hours",
template = "clock24", rotation = "clock", zero = 0, lwd = 1,
control.circle = circle.control(lwd = 2.5, cex = 0.5), shrink = 0.7)
title("Total Cholesterol", line = -0.5)
arrows.circular(totChol_1.circ.mean, length = 0.1, lwd = 2, col = "green", shrink = 0.65)
################################################################################
# Add labels to the circular plot
text(x_pos, y_pos, labels = hour_labels, cex = 0.8)
#################################################################################
#################################amt6###########################################
amt6_2 <- circularData2[1]
amt6_2.circ <- circular(amt6_2, units = "hours", template = "clock24")
amt6_2.circ.mean <- mean(amt6_2.circ, na.rm = T)
amt6_2.circ.var <- var(amt6_2.circ, na.rm = T)
plot.circular(amt6_2.circ, col = "blue", cex = 0.72, pch = 16,
stack = TRUE, axes = FALSE, start.sep = 0.05, sep = 0.07,
bins = 72, ticks = FALSE, tcl = 0.05, tol = 0.77, units = "hours",
template = "clock24", rotation = "clock", zero = 0, lwd = 1,
control.circle = circle.control(lwd = 2.5, cex = 2), shrink = 0.7)
title("aMT6s", line = - 0.5)
arrows.circular(amt6_2.circ.mean, length = 0.1, lwd = 2, col = "blue", shrink = 0.65)
################################################################################
# Add labels to the circular plot
text(x_pos, y_pos, labels = hour_labels, cex = 0.8)
#################################saliva cort###########################################
salvCort_2 <- circularData2[2]
salvCort_2.circ <- circular(salvCort_2, units = "hours", template = "clock24")
salvCort_2.circ.mean <- mean(salvCort_2.circ, na.rm = T)
salvCort_2.circ.var <- var(salvCort_2.circ, na.rm = T)
plot.circular(salvCort_2.circ, col = "red", cex = 0.72, pch = 16,
stack = TRUE, axes = FALSE, start.sep = 0.05, sep = 0.07,
bins = 72, ticks = FALSE, tcl = 0.05, tol = 0.77, units = "hours",
template = "clock24", rotation = "clock", zero = 0, lwd = 1,
control.circle = circle.control(lwd = 2.5, cex = 0.5), shrink = 0.7)
title("Salivary Cortisol", line = - 0.5)
arrows.circular(salvCort_2.circ.mean, length = 0.1, lwd = 2, col = "red", shrink = 0.65)
################################################################################
# Add labels to the circular plot
text(x_pos, y_pos, labels = hour_labels, cex = 0.8)
#################################Urin cort###########################################
urnCort_2 <- circularData2[[3]]
urnCort_2.circ <- circular(urnCort_2, units = "hours", template = "clock24")
urnCort_2.circ.mean <- mean(urnCort_2.circ, na.rm = T)
urnCort_2.circ.var <- var(urnCort_2.circ, na.rm = T)
plot.circular(urnCort_2.circ, col = "orange", cex = 0.72, pch = 16,
stack = TRUE, axes = FALSE, start.sep = 0.05, sep = 0.07,
bins = 72, ticks = FALSE, tcl = 0.05, tol = 0.77, units = "hours",
template = "clock24", rotation = "clock", zero = 0, lwd = 1,
control.circle = circle.control(lwd = 2.5, cex = 0.5), shrink = 0.7)
title("Urinary Cortisol", line = - 0.5)
arrows.circular(urnCort_2.circ.mean, length = 0.1, lwd = 2, col = "orange", shrink = 0.65)
################################################################################
# Add labels to the circular plot
text(x_pos, y_pos, labels = hour_labels, cex = 0.8)
#################################Total Cholesterol###########################################
totChol_2 <- circularData2[4]
totChol_2.circ <- circular(totChol_2, units = "hours", template = "clock24")
totChol_2.circ.mean <- mean(totChol_2.circ, na.rm = T)
totChol_2.circ.var <- var(totChol_2.circ, na.rm = T)
plot.circular(totChol_2.circ, col = "green", cex = 0.72, pch = 16,
stack = TRUE, axes = FALSE, start.sep = 0.05, sep = 0.07,
bins = 72, ticks = FALSE, tcl = 0.05, tol = 0.77, units = "hours",
template = "clock24", rotation = "clock", zero = 0, lwd = 1,
control.circle = circle.control(lwd = 2.5, cex = 0.5), shrink = 0.7)
title("Total Cholesterol", line = -0.5)
arrows.circular(totChol_2.circ.mean, length = 0.1, lwd = 2, col = "green", shrink = 0.65)
################################################################################
# Add labels to the circular plot
text(x_pos, y_pos, labels = hour_labels, cex = 0.8)
####################### Fused #############################################
#################################amt6###########################################
amt6_3 <- circularData3[1]
amt6_3.circ <- circular(amt6_3, units = "hours", template = "clock24")
amt6_3.circ.mean <- mean(amt6_3.circ, na.rm = T)
amt6_3.circ.var <- var(amt6_3.circ, na.rm = T)
plot.circular(amt6_3.circ, col = "blue", cex = 0.72, pch = 16,
stack = TRUE, axes = FALSE, start.sep = 0.05, sep = 0.07,
bins = 72, ticks = FALSE, tcl = 0.05, tol = 0.77, units = "hours",
template = "clock24", rotation = "clock", zero = 0, lwd = 1,
control.circle = circle.control(lwd = 2.5, cex = 2), shrink = 0.7)
title("aMT6s", line = - 0.5)
arrows.circular(amt6_3.circ.mean, length = 0.1, lwd = 2, col = "blue", shrink = 0.65)
################################################################################
# Add labels to the circular plot
text(x_pos, y_pos, labels = hour_labels, cex = 0.8)
#################################saliva cort###########################################
salvCort_3 <- circularData3[2]
salvCort_3.circ <- circular(salvCort_3, units = "hours", template = "clock24")
salvCort_3.circ.mean <- mean(salvCort_3.circ, na.rm = T)
salvCort_3.circ.var <- var(salvCort_3.circ, na.rm = T)
plot.circular(salvCort_3.circ, col = "red", cex = 0.72, pch = 16,
stack = TRUE, axes = FALSE, start.sep = 0.05, sep = 0.07,
bins = 72, ticks = FALSE, tcl = 0.05, tol = 0.77, units = "hours",
template = "clock24", rotation = "clock", zero = 0, lwd = 1,
control.circle = circle.control(lwd = 2.5, cex = 0.5), shrink = 0.7)
title("Salivary Cortisol", line = - 0.5)
arrows.circular(salvCort_2.circ.mean, length = 0.1, lwd = 2, col = "red", shrink = 0.65)
################################################################################
# Add labels to the circular plot
text(x_pos, y_pos, labels = hour_labels, cex = 0.8)
#################################Urin cort###########################################
urnCort_3 <- circularData3[[3]]
urnCort_3.circ <- circular(urnCort_3, units = "hours", template = "clock24")
urnCort_3.circ.mean <- mean(urnCort_3.circ, na.rm = T)
urnCort_3.circ.var <- var(urnCort_3.circ, na.rm = T)
plot.circular(urnCort_3.circ, col = "orange", cex = 0.72, pch = 16,
stack = TRUE, axes = FALSE, start.sep = 0.05, sep = 0.07,
bins = 72, ticks = FALSE, tcl = 0.05, tol = 0.77, units = "hours",
template = "clock24", rotation = "clock", zero = 0, lwd = 1,
control.circle = circle.control(lwd = 2.5, cex = 0.5), shrink = 0.7)
title("Urinary Cortisol", line = - 0.5)
arrows.circular(urnCort_3.circ.mean, length = 0.1, lwd = 2, col = "orange", shrink = 0.65)
################################################################################
# Add labels to the circular plot
text(x_pos, y_pos, labels = hour_labels, cex = 0.8)
#################################Total Cholesterol###########################################
totChol_3 <- circularData3[4]
totChol_3.circ <- circular(totChol_3, units = "hours", template = "clock24")
totChol_3.circ.mean <- mean(totChol_3.circ, na.rm = T)
totChol_3.circ.var <- var(totChol_3.circ, na.rm = T)
plot.circular(totChol_3.circ, col = "green", cex = 0.72, pch = 16,
stack = TRUE, axes = FALSE, start.sep = 0.05, sep = 0.07,
bins = 72, ticks = FALSE, tcl = 0.05, tol = 0.77, units = "hours",
template = "clock24", rotation = "clock", zero = 0, lwd = 1,
control.circle = circle.control(lwd = 2.5, cex = 0.5), shrink = 0.7)
title("Total Cholesterol", line = -0.5)
arrows.circular(totChol_3.circ.mean, length = 0.1, lwd = 2, col = "green", shrink = 0.65)
################################################################################
# Add labels to the circular plot
text(x_pos, y_pos, labels = hour_labels, cex = 0.8)
###################### Transform shrink values ##############################
# # Function to transform a single value to a new range
# transform_variable <- function(value, new_min = 0.3, new_max = 0.6) {
# original_min <- 0 # Set the original min value (you can define it according to your needs)
# original_max <- 1 # Set the original max value (you can define it according to your needs)
# return(new_min + (value - original_min) * (new_max - new_min) / (original_max - original_min))
# }
#
# shrink_factor_amt6 <- transform_variable(shrink_factor_amt6)
# shrink_factor_salvCort <- transform_variable(shrink_factor_salvCort)
# shrink_factor_totCholesterol <- transform_variable(shrink_factor_totCholesterol)
# shrink_factor_urinCort <- transform_variable(shrink_factor_urinCort)
# ############################ Graphs ##########################################
# labelsGraph = c("6", "3", "0", "21", "18", "15", "12", "9")
#
# par(mfrow = c(2,2))
# plot.circular(amt6.circ, stack = TRUE, main = "aMT6s",col = "blue", axes = FALSE, sep = 0.05, start.sep = 0.02)
# symbols(0, 0, circles = 1, inches = FALSE, add = TRUE, lwd = 2)
# axis.circular(at=circular(seq(0, 2*pi - pi/4, by = pi/4)), labels=labelsGraph, tick = F, tcl.text = 0.2)
# arrows.circular(amt6.circ.mean, col = "black", shrink = 0.65, length = 0.1, lwd = 3, angle = 20)
#
# plot.circular(salvCort.circ, stack = TRUE, main = "Saliva Cortisol", col = "red", axes = FALSE, sep = 0.05, start.sep = 0.02)
# symbols(0, 0, circles = 1, inches = FALSE, add = TRUE, lwd = 2)
# axis.circular(at=circular(seq(0, 2*pi - pi/4, by = pi/4)), labels=labelsGraph, tick = F, tcl.text = 0.2)
# arrows.circular(salvCort.circ.mean, shrink = 0.65, col = "black", length = 0.1, lwd = 2, angle = 20)
#
# plot.circular(urinCort.circ, stack = TRUE, main = "Urine Cortisol", col = "orange", axes = FALSE, sep = 0.05, start.sep = 0.02)
# symbols(0, 0, circles = 1, inches = FALSE, add = TRUE, lwd = 2)
# axis.circular(at=circular(seq(0, 2*pi - pi/4, by = pi/4)), labels=labelsGraph, tick = F, tcl.text = 0.2)
# arrows.circular(urinCort.circ.mean, shrink = 0.65, col = "black", length = 0.1, lwd = 2, angle = 20)
#
# plot.circular(totCholesterol.circ, stack = TRUE, main = "Total Cholesterol", col = "green", axes = FALSE, sep = 0.05, start.sep = 0.02)
# symbols(0, 0, circles = 1, inches = FALSE, add = TRUE, lwd = 2)
# axis.circular(at=circular(seq(0, 2*pi - pi/4, by = pi/4)), labels=labelsGraph, tick = F, tcl.text = 0.2)
# arrows.circular(totCholesterol.circ.mean, shrink = 0.65, col = "black", length = 0.1, lwd = 2, angle = 20)
#
# par(mfrow = c(1, 1))
#
# ########################### Table #############################
# Circular_Data_Summary <- data.frame(
# Variable = c("Urinary aMT6s", "Saliva Cort", "Urine Cort", "Total Cholesterol"),
# Mean = round(c(amt6.circ.mean, salvCort.circ.mean, urinCort.circ.mean, totCholesterol.circ.mean), 3),
# Variance = round(c(amt6.circ.var, salvCort.circ.var, urinCort.circ.var, totCholesterol.circ.var), 3)
# )
#
# print(summary_table)
#
# write.csv(Circular_Data_Summary, "Circular_Data_Summary.csv", row.names = FALSE)
#
# ##############################################################
#
# circularData <- read_excel("Example data.xlsx")
#
# #################################amt6###########################################
#
# amt6 <- circularData$aMT6s
#
# amt6.circ <- circular(amt6, units = "hours", template = "clock24")
# amt6.circ.mean <- mean(amt6.circ, na.rm = T)
# amt6.circ.var <- var(amt6.circ, na.rm = T)
# shrink_factor_amt6 <- 1 - amt6.circ.var
#
# # 1. Input: hours from your data
# hours <- amt6
# # Convert to radians (0–24 hours → 0–2π)
# # 1. Input: hours from your data
#
#
# # 2. Convert hours to radians (0–24h → 0–2π)
# radians <- (hours / 24) * 2 * pi
#
# # 3. Create circular object
# x <- circular(radians,
# units = "radians",
# template = "clock24",
# modulo = "2pi",
# zero = 0,
# rotation = "clock")
#
# # 4. Plot using your custom layout
# plot.circular(x,
# cex = 0.72,
# pch = 16,
# stack = TRUE,
# axes = FALSE,
# start.sep = 0.1,
# sep = 0.25,
# shrink = 1.50,
# bins = 72,
# ticks = FALSE,
# tcl = 0.05,
# tol = 0.77,
# units = "hours",
# template = "clock24",
# rotation = "clock",
# zero = 0,
# lwd = 1,
# col = 19,
# control.circle = circle.control(lwd = 2.5, cex = 0.5))
#
# # 5. Calculate mean direction and vector length from CircStats
# mean_dir <- circ.mean(radians)
# rho <- est.rho(radians)
#
# # 6. Draw mean arrow
# arrows.circular(mean_dir,
# length = 0.1,
# lwd = 2,
# col = "red",
# shrink = 0.65)
#
# hour_labels <- c("0", "3", "6", "9", "12", "15", "18", "21")
# hour_pos <- as.numeric(hour_labels)
#
# # Adjust angles for clock24 template (clockwise, 0 at top)
# label_angles <- (0.5 * pi - (hour_pos / 24) * 2 * pi) %% (2 * pi)
#
# # Compute coordinates for labels
# x_pos <- 0.8 * cos(label_angles)
# y_pos <- 0.8 * sin(label_angles)
#
# # Add labels to the circular plot
# text(x_pos, y_pos, labels = hour_labels, cex = 0.8)