Skip to content

Commit 6caa8d8

Browse files
committed
final commit
1 parent b92bc05 commit 6caa8d8

50 files changed

Lines changed: 535 additions & 318 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AssumptionPlotter/DESCRIPTION

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
Package: AssumptionPlotter
22
Type: Package
3-
Title: Assumption Plotter
3+
Title: AssumptionPlotter
44
Version: 0.1.0
55
Authors@R: c(
66
person(
77
"Emma", "Akrong",
8-
email = "emma.akrong@student.uva.nl",
8+
email = "emma.akrong@gmail.com",
99
role = c("aut", "cre")
1010
)
1111
)
12-
Description: This package attempt to provide an intuitive visualization of whether
13-
the user's dataset meets the assumptions of statistical models, as well as
14-
whether a statistical model is expected to capture what the user wants
15-
the model to capture.
12+
Description: This package creates an app that allows for visual inspection of
13+
EMA/ESM data. The purpose is to give EMA/ESM researchers a nice overview of
14+
what their data looks like, and possibly guide decisions on what statistical
15+
model to use. It was developed with the datasets from openESM in mind, and
16+
can currently plot built-in datasets, the users own data, and data from
17+
openESM accessed through the link to download the tsv file in its dedicated
18+
Zenodo page.
19+
1620
License:
1721
Encoding: UTF-8
1822
LazyData: true
1923
RoxygenNote: 7.3.2
2024
Config/testthat/edition: 3
2125
Imports:
2226
bslib,
23-
datasets,
2427
dplyr,
2528
DT,
2629
ggplot2,
30+
grDevices,
2731
knitr,
2832
quarto,
2933
readr,

AssumptionPlotter/NAMESPACE

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
export(assumption_plot)
44
export(clean_df)
5-
export(data_log_plot)
65
export(pie_bar_chart)
6+
export(rank_participants)
77
export(run_plotter)
8-
export(simulate_logistic)
98
import(bslib)
10-
import(datasets)
119
import(dplyr)
1210
import(ggplot2)
1311
import(grDevices)
Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -254,123 +254,3 @@ assumption_plot <- function(
254254

255255

256256

257-
#' Pie or Bar Chart of Missing Data
258-
#'
259-
#' @details
260-
#' This function creates a piechart of all missing data points
261-
#' @param df Selected dataset.
262-
#' @param participant Participant being plotted
263-
#' @param type Whether it should return a pie or bar chart.
264-
#' @param plot_all Whether the function should generate a plot for everyone or only.
265-
#' @param text_font Font style.
266-
#' @param axis_text_size Text sixe of axes.
267-
#' @param legend_text_size Text size of legend.
268-
#' @param theme_choice The bar chart has the same theme as the assumption plot
269-
#' the participant
270-
#' @return A pie or bar chart showing the ratio of missing values for either a
271-
#' participant or the entire dataset.
272-
#' @import ggplot2
273-
#' @import dplyr
274-
#' @import tidyr
275-
#' @export
276-
#' @examples
277-
#' \dontrun{
278-
#' pie_bar_chart(
279-
#' df,
280-
#' participant,
281-
#' type = c("pie", "bar"),
282-
#' plot_all = FALSE,
283-
#' text_font = c("sans", "serif", "mono"),
284-
#' axis_text_size = 12,
285-
#' legend_text_size = 12,
286-
#' theme_choice = c("classic", "minimal", "bw", "void")
287-
#' )
288-
#' }
289-
#'
290-
#'
291-
292-
293-
pie_bar_chart <- function(df,
294-
participant,
295-
type = "pie",
296-
plot_all = FALSE,
297-
text_font = "sans",
298-
axis_text_size = 12,
299-
legend_text_size = 12,
300-
theme_choice = "classic"){
301-
302-
# Subset data if we are not plotting everyone
303-
if(!plot_all){
304-
df <- df %>%
305-
filter(id == participant)
306-
}else{
307-
df <- df
308-
}
309-
310-
311-
# Keep relevant variables
312-
missing <- df$missing
313-
314-
315-
# Make df
316-
plot_df <- data.frame(
317-
Missing = missing
318-
)
319-
320-
plot_df <- df %>%
321-
mutate(Status = ifelse(missing, "Missing", "Included")) %>%
322-
dplyr::count(Status)
323-
324-
325-
# Create different types of plots
326-
if(type == "pie"){
327-
328-
p <-
329-
ggplot(plot_df, aes(x = "", y = n, fill = Status)) +
330-
geom_bar(stat = "identity", width = 1) +
331-
coord_polar("y", start = 0)+
332-
scale_fill_manual(values =
333-
c("Missing" = "red",
334-
"Included" = "blue"))+
335-
theme_void(base_family = text_font)+
336-
theme(
337-
legend.title = element_text(size = legend_text_size+2),
338-
legend.text = element_text(size = legend_text_size)
339-
)
340-
} else if(type == "bar"){
341-
p <-
342-
ggplot(plot_df, aes(x = Status, y = n, fill = Status)) +
343-
geom_col() +
344-
xlab("Data points")+
345-
ylab("Count")+
346-
scale_fill_manual(values =
347-
c("Missing" = "red",
348-
"Included" = "blue"))
349-
350-
351-
# Change theme
352-
p <- switch(theme_choice,
353-
minimal = p + theme_minimal(base_family = text_font),
354-
classic = p + theme_classic(base_family = text_font),
355-
bw = p + theme_bw(base_family = text_font),
356-
void = p + theme_void(base_family = text_font),
357-
p)
358-
359-
# Edit font size
360-
p <- p +
361-
theme(
362-
text = element_text(size = axis_text_size),
363-
axis.title = element_text(size = axis_text_size+2),
364-
axis.text = element_text(size = axis_text_size),
365-
legend.title = element_text(size = legend_text_size+2),
366-
legend.text = element_text(size = legend_text_size)
367-
)
368-
369-
370-
}
371-
372-
return(p)
373-
374-
}
375-
376-

AssumptionPlotter/R/data_log_plot.R

Lines changed: 0 additions & 50 deletions
This file was deleted.

AssumptionPlotter/R/external_packages.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
#' @import knitr
55
#' @import quarto
66
#' @import shiny
7-
#' @import datasets
87
#' @import bslib
98
#' @importFrom DT renderDT DTOutput
109
#' @import sass
1110
#' @importFrom readr read_tsv read_csv
11+
#' @import dplyr
12+
#' @import tidyr
13+
#' @import grDevices
14+
1215
NULL
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#' Pie or Bar Chart of Missing Data
2+
#'
3+
#' @details
4+
#' This function creates a piechart of all missing data points
5+
#' @param df Selected dataset.
6+
#' @param participant Participant being plotted
7+
#' @param type Whether it should return a pie or bar chart.
8+
#' @param plot_all Whether the function should generate a plot for everyone or only.
9+
#' @param text_font Font style.
10+
#' @param axis_text_size Text sixe of axes.
11+
#' @param legend_text_size Text size of legend.
12+
#' @param theme_choice The bar chart has the same theme as the assumption plot
13+
#' the participant
14+
#' @return A pie or bar chart showing the ratio of missing values for either a
15+
#' participant or the entire dataset.
16+
#' @import ggplot2
17+
#' @import dplyr
18+
#' @import tidyr
19+
#' @export
20+
#' @examples
21+
#' \dontrun{
22+
#' pie_bar_chart(
23+
#' df,
24+
#' participant,
25+
#' type = c("pie", "bar"),
26+
#' plot_all = FALSE,
27+
#' text_font = c("sans", "serif", "mono"),
28+
#' axis_text_size = 12,
29+
#' legend_text_size = 12,
30+
#' theme_choice = c("classic", "minimal", "bw", "void")
31+
#' )
32+
#' }
33+
#'
34+
#'
35+
36+
37+
pie_bar_chart <- function(df,
38+
participant,
39+
type = "pie",
40+
plot_all = FALSE,
41+
text_font = "sans",
42+
axis_text_size = 12,
43+
legend_text_size = 12,
44+
theme_choice = "classic"){
45+
46+
# Subset data if we are not plotting everyone
47+
if(!plot_all){
48+
df <- df %>%
49+
filter(id == participant)
50+
}else{
51+
df <- df
52+
}
53+
54+
55+
# Keep relevant variables
56+
missing <- df$missing
57+
58+
59+
# Make df
60+
plot_df <- data.frame(
61+
Missing = missing
62+
)
63+
64+
plot_df <- df %>%
65+
mutate(Status = ifelse(missing, "Missing", "Included")) %>%
66+
dplyr::count(Status)
67+
68+
69+
# Create different types of plots
70+
if(type == "pie"){
71+
72+
p <-
73+
ggplot(plot_df, aes(x = "", y = n, fill = Status)) +
74+
geom_bar(stat = "identity", width = 1) +
75+
coord_polar("y", start = 0)+
76+
scale_fill_manual(values =
77+
c("Missing" = "red",
78+
"Included" = "blue"))+
79+
theme_void(base_family = text_font)+
80+
theme(
81+
legend.title = element_text(size = legend_text_size+2),
82+
legend.text = element_text(size = legend_text_size)
83+
)
84+
} else if(type == "bar"){
85+
p <-
86+
ggplot(plot_df, aes(x = Status, y = n, fill = Status)) +
87+
geom_col() +
88+
xlab("Data points")+
89+
ylab("Count")+
90+
scale_fill_manual(values =
91+
c("Missing" = "red",
92+
"Included" = "blue"))
93+
94+
95+
# Change theme
96+
p <- switch(theme_choice,
97+
minimal = p + theme_minimal(base_family = text_font),
98+
classic = p + theme_classic(base_family = text_font),
99+
bw = p + theme_bw(base_family = text_font),
100+
void = p + theme_void(base_family = text_font),
101+
p)
102+
103+
# Edit font size
104+
p <- p +
105+
theme(
106+
text = element_text(size = axis_text_size),
107+
axis.title = element_text(size = axis_text_size+2),
108+
axis.text = element_text(size = axis_text_size),
109+
legend.title = element_text(size = legend_text_size+2),
110+
legend.text = element_text(size = legend_text_size)
111+
)
112+
113+
114+
}
115+
116+
return(p)
117+
118+
}
119+

AssumptionPlotter/R/missing_data_summary.R renamed to AssumptionPlotter/R/rank_participants.R

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
#' @importFrom dplyr group_by summarise desc slice_head slice_tail
1+
#' Create table that ranks participants after number of missing values
2+
#'
3+
#' @details
4+
#' This function creates the table in the summary tab. It shows the participants
5+
#' with the most and least missing values and the sum and proportion of these
6+
#' missing values.
7+
#' @param df Data frame that has been cleaned with clean_df().
8+
#' @param show How many rows the table should have.
9+
#' @return Table showing the participants with most and least missing values.
10+
#' @import dplyr
11+
#' @export
12+
#' @examples
13+
#' \dontrun{
14+
#' rank_participants(menghini_2013, 5)
15+
#' }
216

317

418
rank_participants <- function(df, show = 5){
@@ -7,8 +21,8 @@ rank_participants <- function(df, show = 5){
721
df <- df[,keep_cols]
822

923
df <- df %>%
10-
dplyr::group_by(id) %>%
11-
dplyr::summarise(
24+
group_by(id) %>%
25+
summarise(
1226
missing_sum = sum(missing, na.rm = TRUE),
1327
missing_prop = mean(missing, na.rm = TRUE)
1428
) %>%

0 commit comments

Comments
 (0)