-
Notifications
You must be signed in to change notification settings - Fork 15
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
Node aesthetics using independently computed data for each node #31
Comments
Hi @kotliary Thanks for giving clustree a go! This is something that is probably a bit hard to do at the moment but hopefully we can come up with a solution that works, I'm sure other people want to do the same thing. Could you provide a full reproducible example that shows what you have tried doing so far, perhaps using the In the mean time I'll have a think about what might work and see if I can come up with something. |
Thank you for the response. Please see an example below. I added a Then I'd like to generate clustree plot with nodes colored by
|
Thanks for the example, that helps a lot! This is something that clustree should be able to do but can't at the moment. I would like to implement it but I am working on some other things at the moment so I don't quite have the time just now. Here is a work around that should be ok for now. Basically we are going to take the layout object, modify it and manually make the plot. Starting from your code above: # Get the graph layout
layout <- clustree(iris_with_groups, prefix = "K", return = "layout") %>%
arrange(node)
# Add the statistic column (or whatever you want to show)
df.test <- arrange(df.test, node)
layout$statistic <- df.test$statistic
# Plot the graph (modified from clustree.R)
gg <- ggraph(layout)
# Add the edges
gg <- gg + geom_edge_link(arrow = arrow(length = unit(1.5 * 5, "points"),
ends = "last"),
end_cap = circle(9.5 * 1.5, "points"),
start_cap = circle(9.5 * 1.5, "points"),
aes_(colour = ~count,
alpha = ~in_prop,
edge_width = ~is_core)) +
scale_edge_width_manual(values = c(1.5, 1.5),
guide = "none") +
scale_edge_colour_gradientn(colours = viridis::viridis(256)) +
scale_edge_alpha(limits = c(0, 1))
# Add the node points (replace "statistic" with the column you want to show)
gg <- gg + clustree:::add_node_points("statistic", "size", 1, colnames(layout))
# Add the node text
gg <- gg + geom_node_text(aes_(label = ~cluster), size = 3,
colour = "black")
# Plot theme
gg <- gg + scale_size(range = c(4, 15)) +
ggraph::theme_graph(base_family = "",
plot_margin = ggplot2::margin(2, 2, 2, 2)) Which gives us this plot. I've shown the |
Works great! Thank you so much! One modification. You cannot use
Other than that it works perfectly. I hope this feature will be integrated into the package at some point. |
You are right about I'm going to close this issue now but I have made a note in #26 about trying to add this as a feature. |
I compute some statistics from predicting models for each cluster and save them in a separate data.frame. But I cannot figure out how to color the clustree nodes by these values. I've tried to directly modify data for returned ggplot object, but with this operation the data is converted to pure data.frame loosing all information on edges.
Any ideas or a workaround?
Thanks for the great package!
The text was updated successfully, but these errors were encountered: