-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.Rhistory
512 lines (512 loc) · 24 KB
/
.Rhistory
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
View(tmp)
?ordered
x <- readr@@read_csv("/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Mesh.Inch.csv")
x <- readr::read_csv("/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Mesh.Inch.csv")
x <- x |>
# dplyr::mutate(ycentred = y - mean(y)) |> # make mean column
# The above exists already in gbm.auto L843
# Also it uses preset colname y produced by gbm.auto.
dplyr::rename("Category" = tidyselect::last_col(offset = 2), # no first_col option
"ycentred" = tidyselect::last_col()) |>
# 2023-08-30 quoted Category to hopefully address gbm.factorplot: no visible binding for global variable ‘Category’
# also need to do for ycentred
dplyr::arrange(ycentred) # re-order the x axis for categorical variables in order from high to low value
View(x)
x <- readr::read_csv("/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year.csv")
View(x)
x <- x |>
# dplyr::mutate(ycentred = y - mean(y)) |> # make mean column
# The above exists already in gbm.auto L843
# Also it uses preset colname y produced by gbm.auto.
dplyr::rename("Category" = tidyselect::last_col(offset = 2), # no first_col option
"ycentred" = tidyselect::last_col()) |> # attempt to address no visible binding for global variable ‘Category’
# 2023-08-30 quoted Category to hopefully address gbm.factorplot: no visible binding for global variable ‘Category’
# also need to do for ycentred
dplyr::arrange("ycentred") # re-order the x axis for categorical variables in order from high to low value
View(x)
x <- x |>
# dplyr::mutate(ycentred = y - mean(y)) |> # make mean column
# The above exists already in gbm.auto L843
# Also it uses preset colname y produced by gbm.auto.
dplyr::rename("Category" = tidyselect::last_col(offset = 2), # no first_col option
"ycentred" = tidyselect::last_col()) |> # attempt to address no visible binding for global variable ‘Category’
# 2023-08-30 quoted Category to hopefully address gbm.factorplot: no visible binding for global variable ‘Category’
# also need to do for ycentred
dplyr::arrange(ycentred) # re-order the x axis for categorical variables in order from high to low value
devtools::document()
devtools::check()
data("iris")
tmp <- iris |> dplyr::mutate("Category" = dplyr::ordered(Sepal.Length))
tmp <- iris |> dplyr::mutate("Category" = ordered(Sepal.Length))
View(tmp)
tmp <- iris |> dplyr::mutate("Category" = ordered(Sepal.Length)) |> arrange(Category)
tmp <- iris |> dplyr::mutate("Category" = ordered(Sepal.Length)) |> dplyr::arrange(Category)
View(tmp)
tmp <- iris |> dplyr::mutate("Category" = ordered(Sepal.Length)) |> dplyr::arrange("Category")
rm(tmp)
tmp <- iris |> dplyr::mutate("Category" = ordered(Sepal.Length)) |> dplyr::arrange("Category")
View(tmp)
rm(tmp)
tmp <- iris |> dplyr::mutate("Category" = ordered("Sepal.Length")) |> dplyr::arrange(Category)
View(tmp)
# cran tests
# attempt to address no visible binding for global variable ‘Category’ and ycentred
mydata <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year.png")
# cran tests
# attempt to address no visible binding for global variable ‘Category’ and ycentred
mydata <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year.csv")
View(mydata)
gbm.auto::gbm.factorplot(x = mydata, ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST")
gbm.auto::gbm.factorplot(x = mydata, ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
gsavewidth = 4*480,
ggsaveheight = 4*480,
ggsaveunits = "px")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
gsavewidth = (4*480),
ggsaveheight = (4*480),
ggsaveunits = "px")
4*480
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
gsavewidth = 1920,
ggsaveheight = 1920,
ggsaveunits = "px")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
gsavewidth = 1920,
ggsaveheight = 1920,
ggsaveunits = "cm")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
gsavewidth = 19,
ggsaveheight = 19,
ggsaveunits = "cm")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
gsavewidth = 30,
ggsaveheight = 19,
ggsaveunits = "cm")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
gsavewidth = 50,
ggsaveheight = 19,
ggsaveunits = "cm")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
gsavewidth = 5,
ggsaveheight = 19,
ggsaveunits = "cm")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
# gsavewidth = 5,
ggsaveheight = 19,
ggsaveunits = "cm")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
# gsavewidth = 5,
ggsaveheight = 9,
ggsaveunits = "cm")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
# gsavewidth = 5,
ggsaveheight = 4*480,
ggsaveunits = "px")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
# gsavewidth = 5,
ggsaveheight = 3*480,
ggsaveunits = "px")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
# gsavewidth = 5,
ggsaveheight = 1*480,
ggsaveunits = "px")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
# gsavewidth = 5,
ggsaveheight = 240,
ggsaveunits = "px")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
ggsavewidth = 4*480,
ggsaveheight = 4*480,
ggsaveunits = "px")
source("~/Dropbox/Galway/Analysis/R/gbm.auto/R/gbm.factorplot.R")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
ggsavewidth = 4*480,
ggsaveheight = 4*480,
ggsaveunits = "px")
source("~/Dropbox/Galway/Analysis/R/gbm.auto/R/gbm.factorplot.R")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
ggsavewidth = 4*480,
ggsaveheight = 4*480,
ggsaveunits = "px")
factorplotlevels = NULL
ggplot2guideaxisangle = 0
ggplot2labsx = ""
ggplot2labsy = "Marginal Effect"
ggplot2axistext = 1.5
ggplot2axistitle = 2
ggplot2legendtext = 1
ggplot2legendtitle = 1.5
ggplot2legendtitlealign = 0
ggplot2plotbackgroundfill = "white"
ggplot2plotbackgroundcolour = "grey50"
ggplot2striptextx = 2
ggplot2panelbordercolour = "black"
ggplot2panelborderfill = NA
ggplot2panelborderlinewidth = 1
ggplot2legendspacingx = grid::unit(0, "cm")
ggplot2legendbackground = ggplot2::element_blank()
ggplot2panelbackgroundfill = "white"
ggplot2panelbackgroundcolour = "grey50"
ggplot2panelgridcolour = "grey90"
ggplot2legendkey = ggplot2::element_blank()
ggsavefilename = paste0(lubridate::today(), "_Categorical-variable.png")
ggsaveplot = ggplot2::last_plot()
ggsavedevice = "png"
ggsavepath = ""
ggsavescale = 2
ggsavewidth = 10
ggsaveheight = 4
ggsaveunits = "in"
ggsavedpi = 300
ggsavelimitsize = TRUE
x = mydata
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png"
ggsavewidth = 4*480
ggsaveheight = 4*480
ggsaveunits = "px"
is.character(x)
if (is.character(x)) {
x <- readr::read_csv(x) # readr::read_csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-03_Frances_Naomi/2023-02-21 categorical variables issue/count_elasmo/Gaus_Best_line_isl_grp.csv")
} else {
x <- x
}
tmp <- x
View(x)
x <- x |>
# dplyr::mutate(ycentred = y - mean(y)) |> # make mean column
# The above exists already in gbm.auto L843
# Also it uses preset colname y produced by gbm.auto.
dplyr::rename("Category" = tidyselect::last_col(offset = 2), # no first_col option
"ycentred" = tidyselect::last_col()) |> # attempt to address no visible binding for global variable ‘Category’
# 2023-08-30 quoted Category to hopefully address gbm.factorplot: no visible binding for global variable ‘Category’
# also need to do for ycentred
dplyr::arrange(ycentred) # re-order the x axis for categorical variables in order from high to low value
is.null(factorplotlevels)
# re-reorder by factorplotlevels if present
if (!is.null(factorplotlevels)) {
# check level number matches x categories
if (length(factorplotlevels) != length(x[, "Category"])) stop("number of factorplotlevels doesn't match number of categories in x") # x$Category
# check names match
if (!all(factorplotlevels %in% x[, "Category"])) stop(paste0("The following level names not present in categories in x: ", # x$Category
factorplotlevels[!factorplotlevels %in% x[, "Category"]])) # x$Category
x <- x |>
dplyr::mutate(Category = ordered(Category, levels = factorplotlevels)) |> # recreate Category as ordered factor with factorplotlevels. Can't quote "Category" in ordered
dplyr::arrange(Category) # arrange by labels (implicit). Can't quote "Category"
} else {
if (is.integer(x$Category)) x <- x |> dplyr::mutate(Category = ordered(Category)) # make integers ordered factor to avoid defaulting to continuous
}
View(x)
ggplot2::ggplot(x) +
ggplot2::geom_col(ggplot2::aes(x = Category, # x[, "Category"]
y = ycentred)) + # x[, "ycentred"]
# rotate x axis labels
ggplot2::guides(x = ggplot2::guide_axis(angle = ggplot2guideaxisangle)) +
# alter axis labels
ggplot2::labs(x = "",
y = "Marginal Effect") +
# change theme elements
ggplot2::theme_minimal() %+replace% ggplot2::theme(
axis.text = ggplot2::element_text(size = ggplot2::rel(ggplot2axistext)),
axis.title = ggplot2::element_text(size = ggplot2::rel(ggplot2axistitle)),
legend.text = ggplot2::element_text(size = ggplot2::rel(ggplot2legendtext)),
legend.title = ggplot2::element_text(size = ggplot2::rel(ggplot2legendtitle)),
legend.title.align = ggplot2legendtitlealign, # otherwise effect type title centre aligned for some reason
plot.background = ggplot2::element_rect(fill = ggplot2plotbackgroundfill,
colour = ggplot2plotbackgroundcolour), # white background
strip.text.x = ggplot2::element_text(size = ggplot2::rel(ggplot2striptextx)),
panel.border = ggplot2::element_rect(colour = ggplot2panelbordercolour,
fill = ggplot2panelborderfill,
linewidth = ggplot2panelborderlinewidth),
legend.spacing.x = ggplot2legendspacingx, # compress spacing between legend items, this is min
legend.background = ggplot2legendbackground,
panel.background = ggplot2::element_rect(fill = ggplot2panelbackgroundfill,
colour = ggplot2panelbackgroundcolour),
panel.grid = ggplot2::element_line(colour = ggplot2panelgridcolour),
legend.key = ggplot2legendkey)
library(ggplot2)
ggplot2::ggplot(x) +
ggplot2::geom_col(ggplot2::aes(x = Category, # x[, "Category"]
y = ycentred)) + # x[, "ycentred"]
# rotate x axis labels
ggplot2::guides(x = ggplot2::guide_axis(angle = ggplot2guideaxisangle)) +
# alter axis labels
ggplot2::labs(x = "",
y = "Marginal Effect") +
# change theme elements
ggplot2::theme_minimal() %+replace% ggplot2::theme(
axis.text = ggplot2::element_text(size = ggplot2::rel(ggplot2axistext)),
axis.title = ggplot2::element_text(size = ggplot2::rel(ggplot2axistitle)),
legend.text = ggplot2::element_text(size = ggplot2::rel(ggplot2legendtext)),
legend.title = ggplot2::element_text(size = ggplot2::rel(ggplot2legendtitle)),
legend.title.align = ggplot2legendtitlealign, # otherwise effect type title centre aligned for some reason
plot.background = ggplot2::element_rect(fill = ggplot2plotbackgroundfill,
colour = ggplot2plotbackgroundcolour), # white background
strip.text.x = ggplot2::element_text(size = ggplot2::rel(ggplot2striptextx)),
panel.border = ggplot2::element_rect(colour = ggplot2panelbordercolour,
fill = ggplot2panelborderfill,
linewidth = ggplot2panelborderlinewidth),
legend.spacing.x = ggplot2legendspacingx, # compress spacing between legend items, this is min
legend.background = ggplot2legendbackground,
panel.background = ggplot2::element_rect(fill = ggplot2panelbackgroundfill,
colour = ggplot2panelbackgroundcolour),
panel.grid = ggplot2::element_line(colour = ggplot2panelgridcolour),
legend.key = ggplot2legendkey)
devtools::document()
source("~/Dropbox/Galway/Analysis/R/gbm.auto/R/gbm.factorplot.R")
rm(list = c("gbm.factorplot"))
devtools::document()
# cran tests
# attempt to address no visible binding for global variable ‘Category’ and ycentred
remotes::install_github("SimonDedman/gbm.auto")
# ctrl shift F10
library(gbm.auto)
mydata <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year.csv")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
ggsavewidth = 4*480,
ggsaveheight = 4*480,
ggsaveunits = "px")
source("~/Desktop/gbm.factorplot-BKUP.R")
devtools::document()
rm(list = c("gbm.factorplot"))
devtools::document()
devtools::check()
# cran tests
# attempt to address no visible binding for global variable ‘Category’ and ycentred
remotes::install_github("SimonDedman/gbm.auto")
# ctrl shift F10
library(gbm.auto)
mydata <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year.csv")
gbm.auto::gbm.factorplot(x = mydata,
ggsavefilename = "/home/simon/Documents/Si Work/PostDoc Work/Kroetz & Dedman Sawfish BRT/P.Pectinata.CPUE.m2/AllExpvars/P.Pectinata.CPUE.m2/Bin_Best_line_Year_ggTEST.png",
ggsavewidth = 4*480,
ggsaveheight = 4*480,
ggsaveunits = "px")
devtools::build()
devtools::check()
devtools::build()
devtools::release()
devtools::document()
devtools::check()
devtools::check_win_devel()
devtools::release()
devtools::document()
devtools::release()
devtools::document()
drumline <- readRDS("/home/simon/Documents/Si Work/PostDoc Work/Saving The Blue/Data/2023-12-18_drumline_reefs_dropoff.rds")
drumline %<>% tidyr::drop_na(CaribbeanReef_CPUE)
library(magrittr) # %<>%
library(dplyr) # %>% matches last filter mutate case_when relocate everything rename across last_col bind_cols group_by tally pull summarise n_distinct left_join arrange select bind_rows # %>% matches last filter mutate case_when relocate everything rename across last_col bind_cols group_by tally pull summarise n_distinct left_join arrange select bind_rows
library(lubridate) # minute yday month is.POSIXt today
library(tidyverse) # "No used functions found" # "No used functions found"
library(tidylog) # filter mutate relocate pivot_wider rename replace_na group_by tally summarise left_join drop_na select pivot_longer # filter mutate relocate pivot_wider rename replace_na group_by tally summarise left_join drop_na select pivot_longer
library(gbm.auto)
source("~/Dropbox/Galway/Analysis/R/My Misc Scripts/lognegs.R")
drumline <- readRDS("/home/simon/Documents/Si Work/PostDoc Work/Saving The Blue/Data/2023-12-18_drumline_reefs_dropoff.rds")
drumline %<>% tidyr::drop_na(CaribbeanReef_CPUE)
samples = as.data.frame(drumline |> filter(CaribbeanReef_CPUE != 0) |> select(CaribbeanReef_CPUE, all_of(expvars))),
samples = as.data.frame(drumline |> filter(CaribbeanReef_CPUE != 0) |> select(CaribbeanReef_CPUE, all_of(expvars)))
drumline <- readRDS("/home/simon/Documents/Si Work/PostDoc Work/Saving The Blue/Data/2023-12-18_drumline_reefs_dropoff.rds")
drumline %<>% tidyr::drop_na(CaribbeanReef_CPUE)
expvars = c(
"Habitat", # Site3 Habitat Substrate2 all similar
"Tide",
"Season",
"LunarPhase",
"Depth_m",
"Temperature_C",
"Yearday",
"DtDropOff"
)
samples = as.data.frame(drumline |> filter(CaribbeanReef_CPUE != 0) |> select(CaribbeanReef_CPUE, all_of(expvars)))
expvar = expvars
# expvar = c("Habitat", "Tide", "LunarPhase", "Depth_m", "Temperature_C", "Yearday", "DtDropOffLogNeg"),
# expvar = c("DtDropOffLogNeg"),
resvar = "CaribbeanReef_CPUE"
# expvarnames = NULL,
# resvarname = NULL,
savedir = paste0("../../Projects/2021-10_Drumline_Reefshark/LMplots PairPlots/")
expvarnames = NULL
resvarname = NULL
plotname = NULL
pngtype = c("cairo-png", "quartz", "Xlib")
r2line = TRUE
pointtext = FALSE
pointlabs = resvar
pointcol = "black"
expvar
i <- "Tide"
print(paste0("plotting ", which(expvar %in% i), "/", length(expvar), ": ", i))
# overwrite xname if expvarnames present
xname <- ifelse(test = is.null(expvarnames),
yes = i,
no = expvarnames[which(expvar %in% i)])
# overwrite plotname if plotname present
plotname <- ifelse(test = is.null(plotname),
yes = xname,
no = plotname[which(expvar %in% i)])
# overwrite yname if resvarname present
yname <- ifelse(test = is.null(resvarname),
yes = resvar,
no = resvarname)
# run plot
gbm.auto::lmplot(
x = samples[, i],
y = samples[, resvar],
xname = xname,
yname = yname,
savedir = savedir,
pngtype = c("cairo-png", "quartz", "Xlib"),
# xlab = xname, # x axis label, parsed from xname unless specified
# ylab = yname, # y axis label, parsed from yname unless specified
plotname = plotname, # filename for png, parsed from xname unless specified
r2line = r2line, # plot rsquared trendline, default TRUE
pointtext = pointtext, # label each point? Default false
pointlabs = pointlabs, # point labels, defaults to resvar value
pointcol = pointcol, # points colour
)
savedir
getwd()
# expvarnames = NULL,
# resvarname = NULL,
savedir = "/home/simon/Documents/Si Work/PostDoc Work/Saving The Blue/Projects/2021-10_Drumline_Reefshark/LMplots PairPlots"
# run plot
gbm.auto::lmplot(
x = samples[, i],
y = samples[, resvar],
xname = xname,
yname = yname,
savedir = savedir,
pngtype = c("cairo-png", "quartz", "Xlib"),
# xlab = xname, # x axis label, parsed from xname unless specified
# ylab = yname, # y axis label, parsed from yname unless specified
plotname = plotname, # filename for png, parsed from xname unless specified
r2line = r2line, # plot rsquared trendline, default TRUE
pointtext = pointtext, # label each point? Default false
pointlabs = pointlabs, # point labels, defaults to resvar value
pointcol = pointcol, # points colour
)
# expvarnames = NULL,
# resvarname = NULL,
savedir = "/home/simon/Documents/Si Work/PostDoc Work/Saving The Blue/Projects/2021-10_Drumline_Reefshark/LMplots PairPlots/"
# run plot
gbm.auto::lmplot(
x = samples[, i],
y = samples[, resvar],
xname = xname,
yname = yname,
savedir = savedir,
pngtype = c("cairo-png", "quartz", "Xlib"),
# xlab = xname, # x axis label, parsed from xname unless specified
# ylab = yname, # y axis label, parsed from yname unless specified
plotname = plotname, # filename for png, parsed from xname unless specified
r2line = r2line, # plot rsquared trendline, default TRUE
pointtext = pointtext, # label each point? Default false
pointlabs = pointlabs, # point labels, defaults to resvar value
pointcol = pointcol, # points colour
)
plotname
plotname = NULL
expvar
for (i in expvar) { # i <- "Tide"
print(paste0("plotting ", which(expvar %in% i), "/", length(expvar), ": ", i))
# overwrite xname if expvarnames present
xname <- ifelse(test = is.null(expvarnames),
yes = i,
no = expvarnames[which(expvar %in% i)])
# overwrite plotname if plotname present
plotnameFun <- ifelse(test = is.null(plotname),
yes = xname,
no = plotname[which(expvar %in% i)])
# overwrite yname if resvarname present
yname <- ifelse(test = is.null(resvarname),
yes = resvar,
no = resvarname)
# run plot
gbm.auto::lmplot(
x = samples[, i],
y = samples[, resvar],
xname = xname,
yname = yname,
savedir = savedir,
pngtype = c("cairo-png", "quartz", "Xlib"),
# xlab = xname, # x axis label, parsed from xname unless specified
# ylab = yname, # y axis label, parsed from yname unless specified
plotname = plotnameFun, # filename for png, parsed from xname unless specified
r2line = r2line, # plot rsquared trendline, default TRUE
pointtext = pointtext, # label each point? Default false
pointlabs = pointlabs, # point labels, defaults to resvar value
pointcol = pointcol, # points colour
)
rm(list("xname", "plotname"))
}
for (i in expvar) { # i <- "Tide"
print(paste0("plotting ", which(expvar %in% i), "/", length(expvar), ": ", i))
# overwrite xname if expvarnames present
xname <- ifelse(test = is.null(expvarnames),
yes = i,
no = expvarnames[which(expvar %in% i)])
# overwrite plotname if plotname present
plotnameFun <- ifelse(test = is.null(plotname),
yes = xname,
no = plotname[which(expvar %in% i)])
# overwrite yname if resvarname present
yname <- ifelse(test = is.null(resvarname),
yes = resvar,
no = resvarname)
# run plot
gbm.auto::lmplot(
x = samples[, i],
y = samples[, resvar],
xname = xname,
yname = yname,
savedir = savedir,
pngtype = c("cairo-png", "quartz", "Xlib"),
# xlab = xname, # x axis label, parsed from xname unless specified
# ylab = yname, # y axis label, parsed from yname unless specified
plotname = plotnameFun, # filename for png, parsed from xname unless specified
r2line = r2line, # plot rsquared trendline, default TRUE
pointtext = pointtext, # label each point? Default false
pointlabs = pointlabs, # point labels, defaults to resvar value
pointcol = pointcol, # points colour
)
}
samples <- read.csv("~/Downloads/catchdata_2001-2020_USETHISONEforBRT.csv", header=FALSE)
View(samples)
library(gbm.auto)
gbm.auto(samples=samples,expvar=c(10:26),resvar=27,lr=c(0.01,0.001),savedir = "/home/simon/Downloads/")
library(tidyverse)
samples <- read_csv("/home/simon/Downloads/data.csv")
gbm.auto(samples=samples,expvar=c(10:26),resvar=27,lr=c(0.01,0.001),savedir = "/home/simon/Downloads/")
usethis::use_mit_license()
document()
devtools::document()
devtools::check
devtools::check()
devtools::document()
devtools::check()
citation("movegroup")
install.packages("GWalkR")
library(GWalkR)
library(tidyverse)
mpg_tbl <- read_csv("083_gwalkr/data/mpg.csv")