Closed higgi13425 closed 2 months ago
Is there a way to handle the 5 distinct withdrawal boxes in the 5 groups with a single case_when statement? These seem to be ids 10, 12, 14, 16, 18
Dear @higgi13425,
Thanks for the post. Looking at your answer I assume that you have managed to see the ids of your flowchart, which is looking at the $fc
tibble of your flowchart (in your case this would be upa_fc6$fc
). To inspect better the tibble you can also view it using the function View()
on your tibble.
To handle the 5 distinct withdrawal boxes you could use a single case_when()
statement without problem. You can see an example of this usage in the Example 2 of the vignette (https://bruigtp.github.io/flowchart/articles/flowchart.html#example-2):
safo |>
as_fc(label = "patients assessed for eligibility", text_pattern = "{n} {label}") |>
fc_filter(!is.na(group), label = "randomized", text_pattern = "{n} {label}", show_exc = TRUE,
just_exc = "left", text_pattern_exc = "{label}", label_exc = label_exc, text_fs_exc = 7) |>
fc_split(group, text_pattern = "{n} asssigned\n {label}") |>
fc_filter(itt == "Yes", label = "included in intention-to-treat\n population", show_exc = TRUE,
text_pattern = "{n} {label}",
label_exc = "patient did not receive allocated\n treatment (withdrew consent)",
text_pattern_exc = "{n} {label}", text_fs_exc = 7) |>
fc_filter(pp == "Yes", label = "included in per-protocol\n population", show_exc = TRUE,
just_exc = "left", text_pattern = "{n} {label}", text_fs_exc = 7) |>
fc_modify(
~.x |>
filter(n != 0) |>
mutate(
text = case_when(id == 11 ~ label_exc1, id == 13 ~ label_exc2, TRUE ~ text),
x = case_when(id == 3 ~ x + 0.15, id %in% c(11, 13) ~ x + 0.01, TRUE ~ x),
y = case_when(id %in% c(1, 3) ~ y + 0.05, id >= 2 ~ y - 0.05, TRUE ~ y)
)
) |>
fc_draw()
The code that your looking for is found in the line text = case_when(id == 11 ~ label_exc1, id == 13 ~ label_exc2, TRUE ~ text)
in which I set a different label for a different id box, using a single case_when()
statement.
Thanks!
(Label as a question) I am hoping to add a 2nd example dataset to this package from a study I was involved in. I am close to completion, but struggling with fc_modify for exclusions. My progress can be seen here https://rpubs.com/phiggins/1202450 I believe that I am building the dataset correctly, but I don't know how to find the ids of new boxes, particularly for withdrawals after randomization. I also have an issue with the order of the groups (treatment arms) that seems odd. Is it alphabetical? Can I control this?
thanks, Peter