diff --git "a/docs/2024-06/_R\345\214\205\345\210\206\344\272\253__flowchart\347\273\230\345\210\266\344\270\260\345\257\214\345\244\232\345\275\251\346\265\201\347\250\213\345\233\276.md" "b/docs/2024-06/_R\345\214\205\345\210\206\344\272\253__flowchart\347\273\230\345\210\266\344\270\260\345\257\214\345\244\232\345\275\251\346\265\201\347\250\213\345\233\276.md" deleted file mode 100644 index efcd598c..00000000 --- "a/docs/2024-06/_R\345\214\205\345\210\206\344\272\253__flowchart\347\273\230\345\210\266\344\270\260\345\257\214\345\244\232\345\275\251\346\265\201\347\250\213\345\233\276.md" +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "[R包分享] flowchart绘制丰富多彩流程图" -date: 2024-06-14T23:58:05Z -draft: ["false"] -tags: [ - "fetched", - "R语言数据分析指南" -] -categories: ["Acdemic"] ---- -[R包分享] flowchart绘制丰富多彩流程图 by R语言数据分析指南 ------- -
❝本节来介绍一款可用于绘制医学类复杂流程图的R包「flowchart」。该包内容丰富可自定义设置参数较多,并配有详细的案例文档,更多详细内容请参考作者的官方文档。
❞
https://bruigtp.github.io/flowchart/articles/flowchart.html
library(tidyverse)
install.packages("flowchart")
library(flowchart)
safo_fc <- safo |>
as_fc(label = "Patients assessed for eligibility") |>
fc_filter(!is.na(group), label = "Randomized", show_exc = TRUE) |>
fc_modify(
~ . |>
mutate(
text = ifelse(id == 3, str_glue("- {sum(safo$inclusion_crit == 'Yes')} not met the inclusion criteria\n- {sum(safo$exclusion_crit == 'Yes')} met the exclusion criteria"), text)
)
)
safo_fc %>% fc_draw()
fc1 <- safo |>
as_fc(label = "Patients assessed for eligibility") |>
fc_filter(itt == "Yes", label = "Intention to treat (ITT)")
fc_draw(fc1)
fc2 <- safo |>
as_fc(label = "Patients assessed for eligibility") |>
fc_filter(pp == "Yes", label = "Per protocol (PP)")
fc_draw(fc2)
list(fc1, fc2) |> fc_merge() |>
fc_draw()
safo |>
as_fc(label = "Patients assessed for eligibility") |>
fc_filter(!is.na(group), label = "Randomized", show_exc = TRUE) |>
fc_split(group) |>
fc_filter(itt == "Yes", label = "Included in ITT") |>
fc_filter(pp == "Yes", label = "Included in PP") |>
fc_draw()
❝下方例子中将展示重现《自然医学》杂志上发表的SAFO研究的原始流程图https://www.nature.com/articles/s41591-023-02569-0/figures/1
❞
label_exc <- paste(
c(str_glue("{sum(safo$inclusion_crit == 'Yes' | safo$exclusion_crit == 'Yes' | safo$decline_part == 'Yes', na.rm = T)} excluded:"),
map_chr(c("inclusion_crit", "decline_part", "exclusion_crit"), ~str_glue("{sum(safo[[.x]] == 'Yes', na.rm = TRUE)} {attr(safo[[.x]], 'label')}")),
map_chr(4:15, ~str_glue(" - {sum(safo[[.x]] == 'Yes')} {attr(safo[[.x]], 'label')}"))),
collapse = "\n")
label_exc <- gsub("exclusion criteria", "exclusion criteria:", label_exc)
safo1 <- safo |>
filter(group == "cloxacillin alone", !is.na(reason_pp)) |>
mutate(reason_pp = droplevels(reason_pp))
label_exc1 <- paste(
c(str_glue("{nrow(safo1)} excluded:"),
map_chr(levels(safo1$reason_pp), ~str_glue(" - {sum(safo1$reason_pp == .x)} {.x}"))),
collapse = "\n")
label_exc1 <- str_replace_all(label_exc1, c("resistant" = "resistant\n", "blood" = "blood\n"))
safo2 <- safo |>
filter(group == "cloxacillin plus fosfomycin", !is.na(reason_pp)) |>
mutate(reason_pp = droplevels(reason_pp))
label_exc2 <- paste(
c(str_glue("{nrow(safo2)} excluded:"),
map_chr(levels(safo2$reason_pp), ~str_glue(" - {sum(safo2$reason_pp == .x)} {.x}"))),
collapse = "\n")
label_exc2 <- str_replace_all(label_exc2, c("nosocomial" = "nosocomial\n", "treatment" = "treatment\n"))
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}", bg_fill_exc="#7294D4",
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()
❝本节介绍到此结束,有需要学习R数据可视化的朋友,欢迎到淘宝店铺R语言数据分析指南,购买小编的R数据可视化案例文档(2024版),「购买将赠送2023年的绘图文档内容」。目前此文档(2023+2024)「已经更新上传了150+案例文档」,每个案例都附有相应的数据和代码,并配有对应的注释文档,方便大家学习和参考。
❞
2024更新的绘图内容同时包含数据+代码+markdown注释文档+文档清单,「小编只分享案例文档不额外回答问题无答疑问。」