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
dna_plotNetwork #206
Comments
Hi,
Instead of using the shorthand, you can use # quick example network
library("rDNA")
dna_init()
conn <- dna_connection(dna_sample())
nw <- dna_network(conn, networkType = "onemode")
att <- dna_getAttributes(conn)
# since the sample does not come wiht an alias, I create one
att$alias <- paste("value", seq_along(att$alias)) To use graph <- dna_toIgraph(nw, attributes = att)
library("ggraph")
#> Loading required package: ggplot2
ggraph(graph, layout = "stress") + # start plot
geom_edge_link(width = 1) + # draw edges
geom_node_point(aes(colour = color), size = 4) + # draw nodes
scale_colour_identity() + # use color attribute to color nodes
geom_node_text(aes(label = alias), vjust = -3, size = 2) + # add labels
scale_y_continuous(expand = c(0.1, 0.1)) + # expand scale a little to prevent cut-off labels
scale_x_continuous(expand = c(0.1, 0.1)) +
theme_graph() Created on 2021-04-11 by the reprex package (v2.0.0) I hope that helps! |
Thanks so much, Johannes.
I tried to run your code using the sample dataset but I was not able to
convert the dna_network object to an igraph object including the attributes.
The error is as follows: "Error in dna_toIgraph(nw, attributes = att) :
unused argument (attributes = att)"
If I do not include the attributes using the code below, then it creates
the object but I'm not able to add the color from the attributes later in
the graph.
graph <- dna_toIgraph(nw)
Is there any extra library that I should use?
I would appreciate your guidance on this.
Paula
El dom, 11 abr 2021 a las 9:22, Johannes Gruber ***@***.***>)
escribió:
… Hi,
dna_plotNetwork is a shorthand for the most common scenarios in rDNA. We
had planned to make it a bit more universal, but unfortunately, none of us
has the time at the moment.
Instead of using the shorthand, you can use ggraph directly thought
(which is the backbone of dna_plotNetwork). Let me show you with a quick
example and you can read more here
<#197 (comment)>:
# quick example network
library("rDNA")
dna_init()conn <- dna_connection(dna_sample())
nw <- dna_network(conn, networkType = "onemode")att <- dna_getAttributes(conn)
# since the sample does not come wiht an alias, I create oneatt$alias <- paste("value", seq_along(att$alias))
To use ggraph, you just have to convert the dna_network object to an
igraph object. To access attributes for one of the variables in the plot,
you have to add them to the igraph object at this point. Simply use:
graph <- dna_toIgraph(nw, attributes = att)
ggraph works very similar to ggplot2. You build your plot up by using
geom* functions which map data to visual representations. You can access
the node data in geom_node* functions.
library("ggraph")#> Loading required package: ggplot2
ggraph(graph, layout = "stress") + # start plot
geom_edge_link(width = 1) + # draw edges
geom_node_point(aes(colour = color), size = 4) + # draw nodes
scale_colour_identity() + # use color attribute to color nodes
geom_node_text(aes(label = alias), vjust = -3, size = 2) + # add labels
scale_y_continuous(expand = c(0.1, 0.1)) + # expand scale a little to prevent cut-off labels
scale_x_continuous(expand = c(0.1, 0.1)) +
theme_graph()
<https://camo.githubusercontent.com/bc2ca0d1b2c9f61d0ed362720c274f0115ce6e5fff6ce12a8e35924d1af539e9/68747470733a2f2f692e696d6775722e636f6d2f354f6a6a6154512e706e67>
Created on 2021-04-11 by the reprex package <https://reprex.tidyverse.org>
(v2.0.0)
I hope that helps!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#206 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARRKJ7APMMJJMXXZJUAZKILTIGPBJANCNFSM42R74BPQ>
.
|
Tagging @TimHenrichsen |
Hi,
I'm trying to create some graphs using the dna_plotNetwork option in R.
I was able to create the graphs using the plot command but there are some options from the dna_plotNetwork that I would like to use, such as layout. I would like to know if there is a way of combining the functions of these two commands. For instance, I would like to use the alias attribute to name the nodes or I would like to set displayisolates to False.
I would appreciate any guidance in this matter.
The text was updated successfully, but these errors were encountered: