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

dna_plotNetwork #206

Open
pauclas opened this issue Apr 8, 2021 · 3 comments
Open

dna_plotNetwork #206

pauclas opened this issue Apr 8, 2021 · 3 comments
Assignees
Labels
rDNA Issues related to rDNA version 2.0 version 3.0 Issues relating to version 3.0, including rDNA
Milestone

Comments

@pauclas
Copy link

pauclas commented Apr 8, 2021

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.

@JBGruber
Copy link
Collaborator

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:

# 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 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()

Created on 2021-04-11 by the reprex package (v2.0.0)

I hope that helps!

@pauclas
Copy link
Author

pauclas commented Apr 13, 2021 via email

@leifeld leifeld added rDNA Issues related to rDNA version 2.0 labels Jan 17, 2022
@leifeld leifeld added this to the DNA 3.0: rDNA milestone Jan 17, 2022
@leifeld leifeld modified the milestones: DNA 3.0.10, DNA 3.0.9 Jan 3, 2023
@leifeld leifeld added the version 3.0 Issues relating to version 3.0, including rDNA label Jan 3, 2023
@leifeld
Copy link
Owner

leifeld commented Jan 3, 2023

Tagging @TimHenrichsen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rDNA Issues related to rDNA version 2.0 version 3.0 Issues relating to version 3.0, including rDNA
Projects
None yet
Development

No branches or pull requests

4 participants