Closed tylerlittlefield closed 4 years ago
look at this amazing hp
starwars_clean <- starwars %>%
tidyr::unnest(vehicles, keep_empty = T) %>%
tidyr::unnest(starships, keep_empty = T) %>%
tidyr::unnest(films, keep_empty = T) %>%
mutate_if(is.character, ~tidyr::replace_na(., "unknown")) %>%
mutate(timeline = case_when(
films %in% c("The Phantom Menace",
"Attack of the Clones",
"Revenge of the Sith") ~ "Prequel",
films %in% c("A New Hope",
"The Empire Strikes Back",
"Return of the Jedi") ~ "Original",
films %in% c("The Force Awakens") ~ "Sequel"
),
chapter = case_when(
films %in% "The Phantom Menace" ~ "Ep 1",
films %in% "Attack of the Clones" ~ "Ep 2",
films %in% "Revenge of the Sith" ~ "Ep 3",
films %in% "A New Hope" ~ "Ep 4",
films %in% "The Empire Strikes Back" ~ "Ep 5",
films %in% "Return of the Jedi" ~ "Ep 6",
films %in% "The Force Awakens" ~ "Ep 7"
)) %>%
arrange(timeline, chapter)
starwars_root <- data.frame(
parent_id = "Star Wars Movies",
child_id = "Star Wars Movies",
child = "Star Wars Movies",
link = "ROOT",
node_type = "ROOT"
)
starwars_layer0 <- starwars_clean %>%
distinct(timeline) %>%
mutate(parent_id = "Star Wars Movies",
child_id = timeline,
child = timeline,
link = timeline,
node_type = timeline)
starwars_layer1 <- starwars_clean %>%
distinct(films, timeline, chapter) %>%
mutate(parent_id = timeline,
child_id = films,
child = films,
link = chapter,
node_type = timeline) %>%
distinct()
starwars_layer2 <- starwars_clean %>%
filter(!starships %in% "unknown") %>%
mutate(parent_id = films,
child_id = starships,
child = starships,
link = "ship",
node_type = "ship") %>%
group_by(parent_id, child_id, child,
link, node_type) %>%
summarize(attributes1 = list(unique(name)))
starwars_df <- bind_rows(starwars_root,
starwars_layer0,
starwars_layer1,
starwars_layer2)
hier_df <- hp_dataframe(starwars_df,
title = "Star Wars Chronicles",
settings = hierplane_settings(attributes = "attributes1") %>%
add_styles(
node_type_to_style = list(
ROOT = c("color1", "strong"),
Prequel = "color3",
Original = "color4",
Sequel = "color2",
ship = "color6"
),
link_to_positions = list(
Prequel = "left",
Original = "right"
),
link_name_to_label = list(
Prequel = "arc",
Sequel = "arc",
Original = "arc"
)
))
hierplane(hier_df)
Close #35
Add package data, readily available to user for demonstration.