如何在 R 中绘制具有不同级别的可折叠树?
我一直在尝试使用 collapsibletree 包绘制可折叠树,但我没有得到我需要的东西。此外,应使用 R 脚本视觉功能将该图上传到 Power BI。
想象一下,我有一个像这样的数据框:
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)
然后,我想绘制一棵可折叠树:
collapsibleTree(df = df,
hierarchy = c("parent", "child"),
root = "Carlos")
但我得到这个结果:
有人知道如何获得该解决方案吗?
提前致谢,祝您有美好的一天!
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 know how to get that solution?
Thanks in advance and have a great day!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的数据中应该具有一个值为
na
的值,因为您需要有一个起点。这就是为什么我在parent> parent
向量为na
中更改您的“”
的原因。之后,您可以使用以下代码:输出:
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 theparent
vector toNA
. After that you can use the following code:Output: