Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65f4c1c
commit 36acd2e
Showing
26 changed files
with
711 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,58 @@ | ||
a17baa8933be5c0dc1ec3c8038cfef9f *DESCRIPTION | ||
6c1de4f16864e7b1fb45a17936f7bb0e *NAMESPACE | ||
a7c511425a89f5e1ba272c6d83e9f186 *NEWS.md | ||
feb1d09c16484dd579cc4c8ec36f2446 *DESCRIPTION | ||
45cdd0b6defddae88ed46ec0a303b8ab *NAMESPACE | ||
112f380ce0b5a0f6f93c0cd26db2d044 *NEWS.md | ||
aac060c746f7fb39344252e5dc59c0fa *R/check_interval.R | ||
08eb33cfabe439bf2a96a423785fec6e *R/count_intervals.R | ||
063e61b4b07a6ee316265d80675abad8 *R/create_byperson.R | ||
3d3cb0c2166278580214a730e8bc1f01 *R/create_bysg.R | ||
4028c3932aebf8331ce911947fc160ea *R/create_bysg.R | ||
41c0a0a109f1fefabfaf6ee77bfa67c8 *R/define_crit1_cutoff.R | ||
1f332dbde40223129c855ae14fb0f639 *R/describe_sg.R | ||
7f260109a0f04c9bf8797b1833fd27e1 *R/extract_values.R | ||
e0618eb1b88fe24d4b0270b6a39309bb *R/identify_sg.R | ||
d4a74abaf8c7d3e92649c8b9980ef8d6 *R/identify_sl.R | ||
17e1f85d4327bc6424d014d9866a73fe *R/describe_sg.R | ||
ba79176a1b3d56398652fc13c1d36a42 *R/extract_values.R | ||
b1c04f7ec7f8f6994205dc7c172bdb60 *R/identify_sg.R | ||
8f8771a45cb3d176b6587b2ff916d43c *R/identify_sl.R | ||
f583f5b5856f7cb5f2c5fbb04f39f8a8 *R/magrittrpipeoperator.R | ||
434aef93ef042b25f382f74f2fc998d6 *R/plot_sg.R | ||
083b47b900877136fdf2be77a90012b8 *R/plot_sg_intervals.R | ||
ebb2ca77c30da10025ed0040b280d9e9 *R/plot_sg_trajectories.R | ||
7ec62cc314be6630849e584257d3369b *R/rename_sg_vars.R | ||
ada6b9546d020f97d23f683340a32efd *R/select_cases.R | ||
37f5111e829a44d26ab17ec9d7ebdf9f *R/sgdata.R | ||
6c89650b927f998ee378b2570a39bb6c *R/sgdata_bad.R | ||
b6b85263aded1c4b3aea9dbb585c677f *R/suddengains.R | ||
2a86f6a260fa4edafb1c8ebce88c094c *R/select_cases.R | ||
31a8e985540e2a7921dd58bb2e31b7a7 *R/sgdata.R | ||
81cb43764280baed3f9e74de701e63f4 *R/suddengains.R | ||
0ab4d8322dd4b7ca36d015518a27cd78 *R/write_byperson.R | ||
1c3614344316647781545e4d54be0163 *R/write_bysg.R | ||
617176aef37d2ac6aac9db2c7b031b65 *README.md | ||
21e285bed5781d1d99e6cc91f19eb481 *build/vignette.rds | ||
637030606613b15e89f2a6a692886d82 *build/vignette.rds | ||
1aae8c00122076a7afbf638c5fffe83e *data/sgdata.RData | ||
abfd6092c9e0e0d6c6f39457778b7215 *data/sgdata_bad.RData | ||
7f082097ed6754bc2180ae9096b6ec70 *inst/CITATION | ||
0ce768e2c0cc6e4fcbcb6ab3405c4879 *inst/doc/suddengains-tutorial.R | ||
b3cb33e055fca09b79b84504da83ec54 *inst/doc/suddengains-tutorial.Rmd | ||
0f700e623878ea0544c70be820481e80 *inst/doc/suddengains-tutorial.html | ||
6b88cd47b56e7d497d071295ee812d69 *inst/doc/shinygains.Rmd | ||
5700856667b8cd9025e502b9997b62f2 *inst/doc/shinygains.html | ||
8355fa5c97a76e94f814272d11471a17 *inst/doc/suddengains-tutorial.R | ||
9760c07f72897bce63f76c6b6a7d1c0b *inst/doc/suddengains-tutorial.Rmd | ||
9aff0fcf32b0d547c252894786b3bfa2 *inst/doc/suddengains-tutorial.html | ||
658676ed1bb999f61dbbc6e5861b6fea *man/check_interval.Rd | ||
8ab622c2774dd46d68838ca0feb7182a *man/count_intervals.Rd | ||
5b7e2b60657464d35a03649b107033a5 *man/create_byperson.Rd | ||
7858361b03b80cd92577eea107607276 *man/create_bysg.Rd | ||
69bd468651d60a79d12cfc12e5519687 *man/define_crit1_cutoff.Rd | ||
b50b79e3e6339a39f9f106f40ca25fd2 *man/describe_sg.Rd | ||
eb4f231ab7b1b359f8e6976642d100d3 *man/describe_sg.Rd | ||
fc27a73033eaa958111140db3ab99781 *man/extract_values.Rd | ||
78245dfb7fa41824ff7f2304bdaec0bb *man/figures/README-unnamed-chunk-4-1.png | ||
1bd025784ffe0997e1d36acb229ef334 *man/figures/README-unnamed-chunk-5-1.png | ||
c551d79f8326f0574a87d84f1d32856e *man/identify_sg.Rd | ||
35c7c344604093a5e1e4becfa9ee880b *man/identify_sl.Rd | ||
df34053394040e7ed49c0c49fc239a67 *man/pipe.Rd | ||
c6a2c63380b4ff14e13d2c8fb7cc0855 *man/plot_sg.Rd | ||
a6e072bc793499cc9038f225e910922f *man/plot_sg_intervals.Rd | ||
53bb0dd86e9fba9d76c737bd7d5136a7 *man/plot_sg_trajectories.Rd | ||
8a528de9d7364d691383a5e2285be409 *man/rename_sg_vars.Rd | ||
042982de74cbde374ab27ed5aec9a5b9 *man/select_cases.Rd | ||
72819e2b60986eb19dd44ef6f9c6d9f8 *man/sgdata.Rd | ||
6ed5432b37bd7ddbaafe6d039f97685f *man/sgdata_bad.Rd | ||
04a76c10a203cf8ec6e211f0cba2ea48 *man/sgdata.Rd | ||
a99a8749a8b18bcdc6f8f7695546de6c *man/sgdata_bad.Rd | ||
989d9928f8fd73578cb8586dd9c71840 *man/write_byperson.Rd | ||
3ad68b79af6841d2fff07144ba1a423c *man/write_bysg.Rd | ||
0622a97a2aaa3c342f09636052c2d7f5 *tests/spelling.R | ||
99f6992a246e4719f00e69e8e7196bfe *vignettes/r-references.bib | ||
b10d7f33763f284d4831a1730fc3f130 *vignettes/references.bib | ||
b3cb33e055fca09b79b84504da83ec54 *vignettes/suddengains-tutorial.Rmd | ||
6b88cd47b56e7d497d071295ee812d69 *vignettes/shinygains.Rmd | ||
9760c07f72897bce63f76c6b6a7d1c0b *vignettes/suddengains-tutorial.Rmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#' Plot summary of available data per time point and analysed session to session intervals | ||
#' | ||
#' @param data A data set in wide format including an ID variable and variables for each measurement point. | ||
#' @param id_var_name String, specifying the name of the ID variable. Each row should have a unique value. | ||
#' @param sg_var_list Vector, specifying the variable names of each measurement point sequentially. | ||
#' @param identify_sg_1to2 Logical, indicating whether to identify sudden losses from measurement point 1 to 2. | ||
#' If set to TRUE, this implies that the first variable specified in \code{sg_var_list} represents a baseline measurement point, e.g. pre-intervention assessment. | ||
#' @return Plot showing percentage of available data per time point and percentage of session to session intervals that wer analysed for sudden gains. | ||
#' @export | ||
#' @import patchwork | ||
#' @examples # Create plot | ||
#' plot_sg_intervals(data = sgdata, | ||
#' id_var_name = "id", | ||
#' sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", | ||
#' "bdi_s4", "bdi_s5", "bdi_s6", | ||
#' "bdi_s7", "bdi_s8", "bdi_s9", | ||
#' "bdi_s10", "bdi_s11", "bdi_s12")) | ||
#' | ||
plot_sg_intervals <- function(data, id_var_name, sg_var_list, identify_sg_1to2 = FALSE) { | ||
|
||
# Select data | ||
sgdata_miss <- data %>% | ||
dplyr::select(id_var_name, sg_var_list) | ||
|
||
# Calculate data for first plot | ||
data_missing <- naniar::miss_var_summary(sgdata_miss) %>% | ||
dplyr::mutate(pct_miss = pct_miss / 100, | ||
pct_available = 1 - pct_miss, | ||
variable = forcats::fct_rev(factor(variable, levels = sg_var_list))) %>% | ||
tidyr::pivot_longer(cols = c("pct_miss", "pct_available")) %>% | ||
dplyr::mutate(name = factor(name, levels = c("pct_miss", "pct_available"), labels = c("Missing Data", "Available Data"))) | ||
|
||
# Create first plot | ||
plot_sg_miss_pct <- data_missing %>% | ||
dplyr::filter(variable != "id") %>% | ||
ggplot2::ggplot(ggplot2::aes(x = variable, y = value, fill = name)) + | ||
ggplot2::geom_bar(position = "fill",stat = "identity") + | ||
# or: | ||
# geom_bar(position = position_fill(), stat = "identity") | ||
ggplot2::scale_y_continuous(labels = scales::percent_format()) + | ||
# scale_fill_manual(values = c("red", "yellow")) | ||
ggplot2::scale_fill_viridis_d(name = "", direction = -1, alpha = .8) + | ||
# papaja::theme_apa() + | ||
ggplot2::labs(title = "Percentage of available data per time point", x = "", y = "") + | ||
ggplot2::theme(legend.position = "right")+ | ||
ggplot2::theme(legend.key = ggplot2::element_rect(color = NA, fill = NA), | ||
legend.key.size = ggplot2::unit(0.9, "cm")) + | ||
ggplot2::theme(legend.title.align = 1.5) + | ||
ggplot2::coord_flip() | ||
|
||
|
||
# Now create date for second plot | ||
count_intervals_data <- suddengains::count_intervals(data = data, | ||
id_var_name = id_var_name, | ||
sg_var_list = sg_var_list) | ||
|
||
plot_count_intervals_data_temp <- tibble::tibble(total = count_intervals_data[[1]], | ||
total_not_available_sg = count_intervals_data[[1]] - count_intervals_data[[2]], | ||
total_between_sess_sg = count_intervals_data[[2]], | ||
available_between_sess_sg = count_intervals_data[[3]], | ||
not_available_between_sess_sg = count_intervals_data[[4]]) %>% | ||
dplyr::select(total_not_available_sg, available_between_sess_sg, not_available_between_sess_sg) %>% | ||
tidyr::pivot_longer(cols = 1:3) %>% | ||
dplyr::mutate(pct = value / count_intervals_data[[1]]) | ||
|
||
|
||
# More data stuff here get things ready for labels legend etc, adding numbers | ||
plot_count_intervals_data <- plot_count_intervals_data_temp %>% | ||
dplyr::mutate(id = "count_intervals", | ||
name = factor(name, | ||
levels = c("not_available_between_sess_sg", "total_not_available_sg", "available_between_sess_sg"), | ||
labels = c(paste0("Not Analysed Type 1\n(n = ", plot_count_intervals_data_temp$value[3],", ", round(plot_count_intervals_data_temp$pct[3] * 100, 0), "%)"), | ||
paste0("Not Analysed Type 2\n(n = ", plot_count_intervals_data_temp$value[1] ,", ", round(plot_count_intervals_data_temp$pct[1] * 100, 0), "%)"), | ||
paste0("Analysed\n(n = ", plot_count_intervals_data_temp$value[2] ,", ", round(plot_count_intervals_data_temp$pct[2] * 100, 0), "%)")))) | ||
|
||
# Create second plot | ||
plot_sg_intervals <- plot_count_intervals_data %>% | ||
ggplot2::ggplot(ggplot2::aes(x = id, y = value, fill = name)) + | ||
ggplot2::geom_bar(position = "fill", stat = "identity") + | ||
ggplot2::scale_fill_viridis_d(name = "", direction = -1, alpha = .8) + | ||
ggplot2::labs(title = "Percentage of session to session intervals analysed", | ||
subtitle = paste0("Total number of intervals, n = ", sum(plot_count_intervals_data_temp$value))) + | ||
ggplot2::theme(legend.position = "right") + | ||
ggplot2::labs(x = "", y = "", caption = "Not Analysed Type 1: The total number of session to session intervals that can not be analysed for sudden gains due to the pattern of missing data.\n\nNot Analysed Type 2: The total number of session to session intervals from the first to the second and the second last to the last session.") + | ||
ggplot2::theme(legend.key = ggplot2::element_rect(color = NA, fill = NA), | ||
legend.key.size = ggplot2::unit(0.9, "cm")) + | ||
ggplot2::theme(legend.title.align = 1.5) + | ||
ggplot2::scale_y_continuous(labels = scales::percent_format(accuracy = 1)) + | ||
ggplot2::theme(axis.text.y = ggplot2::element_blank(), | ||
axis.ticks.y = ggplot2::element_blank(), | ||
plot.caption = ggplot2::element_text(hjust = 0)) + | ||
ggplot2::coord_flip() | ||
|
||
|
||
# Combine Plots | ||
|
||
plot_return <- patchwork::wrap_plots(plot_sg_miss_pct, plot_sg_intervals) + | ||
patchwork::plot_layout(heights = c(4, 1)) + patchwork::plot_annotation(tag_levels = 'A') | ||
|
||
# Return plot | ||
return(plot_return) | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.