Ggraph: "Facets through time"

Created on 22 Sep 2017  Â·  3Comments  Â·  Source: thomasp85/ggraph

Thank you for your amazing package!

I have a question with respect to showing networks across time using facets, where both node and edge characteristics can change over time. I believe that this is currently not available, although it may relate to the igraph-objects that are a bit daunting to me. In essence, I want the different facets to be able to show different node and edge features.

I can best show what I want using the ggnetwork-package (because in this package, igraph/network-objects are turned into dataframes that are more easy to understand):

Packages needed

```{r, results='hide', message=FALSE}
library(dplyr)
library(sna)
library(ggnetwork)

### Creating two (random) networks 
Network with 6 nodes and each node has some characteristic-value. One network is from timepoint 2016, and one from 2017 
```{r}
net_2016 <- network(rgraph(6, tprob = 0.3), directed = FALSE) 
net_2016 %v% "characteristic" <- sample(letters[1:2], 6, replace = TRUE) 
net_2016 %v% "year" <- 2016

net_2017 <- network(rgraph(6, tprob = 0.7), directed = FALSE) 
net_2017 %v% "characteristic" <- sample(letters[1:2], 6, replace = TRUE) 
net_2017 %v% "year" <- 2017

Generating dataframe with ggnetwork based on manually specified coordinates of the 6 nodes and create ggplot

First for "year" 2016:
```{r}

Specify matrix of coordinates for nodes manually

man_coord_matrix <- as.matrix(data.frame(x_c = c(0.5, 1.0, 1.0, 0.5, 0.0, 0.0),
y_c = c(1.00, 0.75, 0.25, 0.00, 0.25, 0.75)))

"Fortifies" network to data.frame, layout specified with manual coordinates

df_net_2016 <- ggnetwork(net_2016, layout = man_coord_matrix)

Create network-plot

ggplot(df_net_2016, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges() +
geom_point(aes(colour=characteristic), size=10) +
geom_nodetext(aes(label = vertex.names),
fontface = "bold", colour="white") +
theme_blank()

![2016](https://user-images.githubusercontent.com/25910562/30742983-ff803238-9f9b-11e7-9a89-2824a02fb5a2.png)

Then for "year" 2017:
```{r}
# "Fortifies" network to data.frame, layout specified with manual coordinates  
df_net_2017 <- ggnetwork(net_2017, layout = man_coord_matrix)

# Create network-plot
ggplot(df_net_2017, aes(x = x, y = y, xend = xend, yend = yend)) +
  geom_edges() +
  geom_point(aes(colour=characteristic), size=10) +
  geom_nodetext(aes(label = vertex.names),
                fontface = "bold", colour="white") +
  theme_blank()

2017

One could now use grid.arrange or some such to create these plots besides one another, but I would very much like facets to be able to do this. With ggnetwork, we can do this by combining the data.frames and facetting on "year":
```{r}

Combine dataframes

df_net_comb <- bind_rows(df_net_2016, df_net_2017)

Create network-plot

ggplot(df_net_comb, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges() +
geom_point(aes(colour=characteristic), size=10) +
geom_nodetext(aes(label = vertex.names),
fontface = "bold", colour="white") +
theme_blank() +
facet_grid(~year)
```
combined

So here we have for "one individual" the network across time; both edge- and node-characteristics can change within the facets.

I have a much harder time envisioning something similar for igraph objects, because you can specify either node-attributes or edge-attributes. Also combining different igraph objects seems difficult Perhaps I am missing something fundamental.

Thanks again for your great package.

New feature

Most helpful comment

Thanks - I have thoughts on this but it all ties into a yet to materialise idea about how to handle dynamic graphs in tidygraph - thus im afraid you'd have to wait a bit for it...

All 3 comments

Thanks - I have thoughts on this but it all ties into a yet to materialise idea about how to handle dynamic graphs in tidygraph - thus im afraid you'd have to wait a bit for it...

No worries. Thank you for taking the time to respond.

More importantly, thank you for your amazing work on the R-packages. I use
them frequently. Your "generative graph art" is also really cool.

G

On Wed, Jan 10, 2018 at 9:31 PM, Thomas Lin Pedersen <
[email protected]> wrote:

Thanks - I have thoughts on this but it all ties into a yet to materialise
idea about how to handle dynamic graphs in tidygraph - thus im afraid you'd
have to wait a bit for it...

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/thomasp85/ggraph/issues/86#issuecomment-356727311,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AYtdIrtRKf6--NwnLaMd7K_AlWwqGwXBks5tJR4vgaJpZM4PgmEO
.

Not facets, but presumably one can gganimate these?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jas1 picture jas1  Â·  14Comments

jalapic picture jalapic  Â·  3Comments

mbojan picture mbojan  Â·  6Comments

Jim89 picture Jim89  Â·  7Comments

daniel-munro picture daniel-munro  Â·  12Comments