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

simplify workflow #448

Closed
ggrothendieck opened this issue Feb 25, 2021 · 4 comments
Closed

simplify workflow #448

ggrothendieck opened this issue Feb 25, 2021 · 4 comments

Comments

@ggrothendieck
Copy link

ggrothendieck commented Feb 25, 2021

The following code seems more complex than I would have thought for something that is pretty simple. Maybe I am missing some feature(s) that already exist but if not consider that we had to add names to prevent the names from changing, then we had to take a subgraph even though the subgraph is the entire graph (it adds nodes if this is not done) and finally plot it. Maybe some feature(s) could be added to make this easier to do.

One other problem which is actually distinct is that what I really wanted was to plot a binary tree showing the left child to the left and right child to the right where even numbered edges are left children and odd numbered edges are right but if there is only one child it plots it beneath so one can't tell whether it is a left or right child.

edges <- structure(c(3, 6, 7, 12, 13, 14, 15, 1, 3, 3, 6, 6, 7, 7), .Dim = c(7L, 
2L), na.action = structure(c(1, 3, 4, 7, 8, 9, 10), class = "omit"))
g <- graph_from_edgelist(edges)

V(g)$name <- V(g)
gs <- induced_subgraph(g, V(g)[V(g) %in% c(edges)])
plot(gs, layout = layout_as_tree(gs, root = 1, mode = "all"))
@gaborcsardi
Copy link
Contributor

g <- graph(as.character(c(3, 1, 6, 3, 7, 3, 12, 6, 13, 6, 14, 7, 15, 7)))
plot(g, layout = layout_as_tree(g, root = "1", mode = "in"))

If you want node labels, then you can use a character edge list.

@ggrothendieck
Copy link
Author

That was what I was missing. Any solution for showing the left child to the left and the right to the right?

@gaborcsardi
Copy link
Contributor

Not that I know of. You can take the calculated coordinates, and post-process them, I guess.

@ggrothendieck
Copy link
Author

ggrothendieck commented Feb 28, 2021

In this SO post

https://stackoverflow.com/questions/66355937/how-to-create-a-binary-tree-using-only-base-r/66356532#66356532

I plotted a binary tree by creating the layout for the full tree and then used the appropriate rows from its layout with the subset of nodes in the actual tree. It works to cause a left child to plot to the left of the parent even if there is no right child and similarly for a right child but I wonder if there could be some feature(s) to make this easier to do.

@ntamas ntamas closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants