Skip to content

Including colors based on a particular node #76

@Cami1992

Description

@Cami1992

Data sample:

data <- data.frame(
Outcome = rep(c("Outcome A", "Outcome B", "Outcome C"), each = 6),
Output = rep(c("Output 1", "Output 2", "Output 3"), times = 6),
Project = paste0("Project ", 1:18),
Expenditure = runif(18, 100, 1000) # Random expenditure values
)

I want to display particular colors based on Outcome (i.e. in total only three colors). But I just got blanks after running the codes:

1° Attempt: collapsibleTree(
data,
hierarchy = c("Outcome", "Output", "Project"),
width_scale = "sqrt",
nodeSize = "Expenditure",
circleFill = c("lightblue", "lightgreen", "lightyellow"), # Custom colors
tooltipLabels = c("Outcome", "Output", "Project", "Expenditure")
)

2° Attempt:

outcome_colors <- c("Outcome A" = "#FF5733", # Color for Outcome1
"Outcome B" = "#33FF57", # Color for Outcome2
"Outcome C" = "#5733FF") # Color for Outcome3

Map colors to outcomes in the data frame

mexico_finance$color <- outcome_colors[mexico_finance$Outcome]
mexico_finance$color<-as.factor(mexico_finance$color)

Use the color palette in your collapsibleTree function

collapsibleTree(
mexico_finance,
hierarchy = c("Outcome", "Output","Project", "Expenditure"),
nodeSize = "Expenditure",
fill = "color", # Use the outcome variable for color
tooltipLabels = c("Outcome", "Output", "Project", "Expenditure"),
width_scale = "sqrt"
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions