Skip to content

Commit b92bc05

Browse files
committed
app works great
1 parent a75db2d commit b92bc05

3 files changed

Lines changed: 169 additions & 59 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#' @importFrom dplyr group_by summarise desc slice_head slice_tail
2+
3+
4+
rank_participants <- function(df, show = 5){
5+
6+
keep_cols <- c("id", "missing")
7+
df <- df[,keep_cols]
8+
9+
df <- df %>%
10+
dplyr::group_by(id) %>%
11+
dplyr::summarise(
12+
missing_sum = sum(missing, na.rm = TRUE),
13+
missing_prop = mean(missing, na.rm = TRUE)
14+
) %>%
15+
arrange(desc(missing_sum))
16+
17+
if(show > nrow(df)){
18+
stop("Selected rows exceed number of participants")
19+
}
20+
21+
most <- df %>%
22+
slice_head(n = show)
23+
24+
least <- df %>%
25+
slice_tail(n = show) %>%
26+
arrange(missing_sum)
27+
28+
rank_df <- data.frame(
29+
"ID_most" = as.character(most$id),
30+
"sum_most" = most$missing_sum,
31+
"prop_most" = paste0(round(most$missing_prop*100),"%"),
32+
"ID_least" = as.character(least$id),
33+
"sum_least" = least$missing_sum,
34+
"prop_least" = paste0(round(least$missing_prop*100),"%")
35+
)
36+
37+
colnames(rank_df) <- c("ID most:",
38+
"Sum",
39+
"Percent",
40+
"ID least:",
41+
"Sum",
42+
"Percent")
43+
44+
return(rank_df)
45+
46+
}
47+
48+

AssumptionPlotter/R/plots.R

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ assumption_plot <- function(
7272
}
7373

7474
# Subset data
75+
## In the future it would be cool to implement the option to plot multiple
76+
## participants at once (so you can compare them).
7577
df <- df %>%
7678
filter(id == participant)
7779

@@ -309,22 +311,22 @@ pie_bar_chart <- function(df,
309311
# Keep relevant variables
310312
missing <- df$missing
311313

312-
# Create group variable
313-
status <- ifelse(missing=="TRUE", "Missing", "Included")
314-
315314

316315
# Make df
317316
plot_df <- data.frame(
318-
Status <- status,
319-
Missing <- missing
317+
Missing = missing
320318
)
321319

320+
plot_df <- df %>%
321+
mutate(Status = ifelse(missing, "Missing", "Included")) %>%
322+
dplyr::count(Status)
323+
322324

323325
# Create different types of plots
324326
if(type == "pie"){
325327

326328
p <-
327-
ggplot(plot_df, aes(x = "", y = Missing, fill = Status)) +
329+
ggplot(plot_df, aes(x = "", y = n, fill = Status)) +
328330
geom_bar(stat = "identity", width = 1) +
329331
coord_polar("y", start = 0)+
330332
scale_fill_manual(values =
@@ -337,8 +339,8 @@ pie_bar_chart <- function(df,
337339
)
338340
} else if(type == "bar"){
339341
p <-
340-
ggplot(plot_df, aes(Status, fill=Status)) +
341-
geom_bar() +
342+
ggplot(plot_df, aes(x = Status, y = n, fill = Status)) +
343+
geom_col() +
342344
xlab("Data points")+
343345
ylab("Count")+
344346
scale_fill_manual(values =
@@ -368,5 +370,7 @@ pie_bar_chart <- function(df,
368370
}
369371

370372
return(p)
373+
371374
}
372375

376+

0 commit comments

Comments
 (0)