-
Notifications
You must be signed in to change notification settings - Fork 116
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
Documentation on geom_edge_link incomplete #363
Comments
ggraph works under the assumption that edge data is always coming from a call to So the omission is fully intended |
Then I would pose the more general question of how ggraph could get closely aligned with the grammar of graphics in the long run. Don't get me wrong, ggraph supports mostly everything I need. But as it stands it requires me to manually prepare a tibble with x and y coordinates from the original layout. That's not as much of an abstraction from using ggplot with x and y coordinates as ggraph was going for. Here is a mock workflow based on my current work which is based on the typical ggplot workflow, and which the documentation on ggraph doesn't cover yet. graph <- as_tbl_graph(df)
layout <- create_layout(graph, layout = "fr")
subset_a <- get_nodes()(layout) %>%
filter(name %in% group_a) %>%
left_join(attribute_df, by = c("name" = "from"))
subset_b <- get_nodes()(layout) %>%
filter(name %in% group_b)
edges <- get_edges("short")(layout) %>%
group_by(from, to) %>%
mutate(connections = n()) %>%
slice_head(n = 1)
ggraph(layout) +
geom_node_point(data = subset_a, aes(size = attribute), shape = 23) +
geom_node_point(data= subset_b) +
geom_edge_arc(data = edges, aes(width = connections)) Let me know if you would like me to open a new issue for this discussion. |
There is no plan to get more "closely aligned with the grammar of graphics". In the example above, the operations should be handled by tidygraph and is not described in the ggraph docs for the same reason that dplyr isn't covered in the ggplot2 docs. In general you prepare your graph with tidygraph and plot it with ggraph. Since network plots are fully reliant on the underlying network it does not make much sense to mix and match small datasets like you are trying to. If you want to only plot a subset of edges, use the filter aesthetic which is available for all ggraph geoms |
I will close the issue then. But I will say that the filter aesthetic is a very dissatisfying solution, especially for more complex conditions. Instead of being able to quickly grab some observations and drop them in, I have to go back and create an additional column in the original data just to turn them on and off. Never needed to do this in ggraph, and I don't see why you are trying to reinvent the wheel here. |
An aesthetic can be an expression and have access to tidygraph algorithms so it is actually quite flexible and powerful, e.g. ggraph is a standard ggplot2 extension so you can use whatever other geoms you want if you don't want to buy into the network idea for all your layers. There is nothing stopping you from adding a |
I see what you mean with that example. In line with that, the filter aesthetic should probably take a more prominent position in the documentation. As it stands, it is just a bullet point in the manual page for geom_edge_link. It's also only covered by one example in the documentation, and that's one that uses one of the built-in attributes, not a custom one. I would also be apprehensive to write a complex filtering logic into a function argument. Looking forward to eventually seeing more examples on that in the documentation -- I know you were busy with the major version release recently. Ideally longer examples that start with some of the well-known included datasets as well. I suppose the intended workflow would be:
Gplot functions are a decent fallback, but using them really negates any advantages that the ggraph package would have. Users need to understand the underlying data structure to use ggplot functions with ggraph, so all ease of use features of ggraph are then out the window and it's back to square one. Of course, that such is the nature of networks, where there are always two separate dataframes/tibbles that make up the data.
I'm sure there are more pressing issues right now, but one option might be to at some point creat a vignette on advanced ggraph, similar to the "Programming with dplyr" vignette? |
On the data argument, the documentation on geom_edge_links states:
However, in neither place is there sufficient information to make the data argument on geom_edge_links work. A reproducible example would be great. Below is a hypothetical example I have been trying to work with. My overall goal would be to apply the geom_edge_link function or a related function to a subset of edges. You will notice that all the error messages say at their core that "object 'edge.id' not found," which does not help much.
Here is the setup:
Here is what I've tried.
get_edges
to extract the corresponding coordinates?get_edges(plot)
Well, I don't know what I expected, but not for this to return a function.
The text was updated successfully, but these errors were encountered: