Skip to content

Commit

Permalink
add labels to decision tree example
Browse files Browse the repository at this point in the history
  • Loading branch information
nrennie committed Oct 14, 2023
1 parent 6d77ba7 commit 4613d4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions slides/R/rf.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ library(ggplot2)

# decision tree
plot_data <- tibble::tribble(
~from, ~to,
"Is it raining?", "Will it rain later?",
"Is it raining?", "Will it be windy later?",
"Will it rain later?", "Walk1",
"Will it rain later?", "Don't Walk1",
"Will it be windy later?", "Walk2",
"Will it be windy later?", "Don't Walk2",
~from, ~to, ~label,
"Is it raining?", "Will it rain later?", "No",
"Is it raining?", "Will it be windy later?", "Yes",
"Will it rain later?", "Walk1", "No",
"Will it rain later?", "Don't Walk1", "Yes",
"Will it be windy later?", "Walk2", "No",
"Will it be windy later?", "Don't Walk2", "Yes"
)
node_data <- tibble::tibble(name = unique(c(plot_data$from, plot_data$to))) %>%
node_data <- tibble::tibble(name = unique(c(plot_data$from, plot_data$to))) |>
dplyr::mutate(label = gsub("\\d+$", "", name),
colour = c(rep("white", 3), "#bec0c2", "#b20e10", "#bec0c2", "#b20e10"))
colour = c(rep("white", 3), "#bec0c2", "#b20e10", "#bec0c2", "#b20e10")) |>
dplyr::mutate(label = stringr::str_wrap(label, 13))
ggflowchart(plot_data, node_data, fill = colour,
alpha = 0.5, x_nudge = 0.5,
text_size = 7) +
text_size = 4.2) +
labs(title = "Should I walk to work?") +
scale_fill_identity() +
theme_void(base_size = 24)
theme_void(base_size = 20)
ggsave("slides/images/rf_01.png", width = 4, height = 4, units = "in")


Binary file modified slides/images/rf_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4613d4a

Please sign in to comment.