Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including colors based on a particular node #76

Open
Cami1992 opened this issue Apr 22, 2024 · 0 comments
Open

Including colors based on a particular node #76

Cami1992 opened this issue Apr 22, 2024 · 0 comments

Comments

@Cami1992
Copy link

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"
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant