I have been trying to plot a collapsible tree with "collapsibletree" package but I don't get what I need. Also, this plot should be uploaded to power BI using the R script visual feature.
Imagine that I have a dataframe like this:
parent <- c("", "Carlos", "Carlos", "María", "María", "Paula", "Alex")
child <- c("Carlos", "María", "Alex", "Javier", "Paula", "Pablo", "Pepe")
df <- data.frame(parent, child)
And then, I want to plot a collapsible tree:
collapsibleTree(df = df,
hierarchy = c("parent", "child"),
root = "Carlos")
But I get this result:
And the result I want is this:
Does anyone knows how to get that solution?
Thanks in advance and have a great day!!
CodePudding user response:
You should have one value as NA
in your data, because you need to have a beginning point. That's why I changed your ""
in the parent
vector to NA
. After that you can use the following code:
parent <- c(NA, "Carlos", "Carlos", "María", "María", "Paula", "Alex")
child <- c("Carlos", "María", "Alex", "Javier", "Paula", "Pablo", "Pepe")
df <- data.frame(parent, child)
library(collapsibleTree)
collapsibleTreeNetwork(df, collapsed = FALSE)
Output: