briatte / ggnetwork

Geoms to plot networks with ggplot2
https://briatte.github.io/ggnetwork/
146 stars 28 forks source link

ggplot(n) returns blank plot #71

Open Fred-White94 opened 2 years ago

Fred-White94 commented 2 years ago

As the title describes. I cannot get the ggplot method to plot my own network or even the network from the tutorial. The network is created and can be visualised (not so nicely) with plot(n) but ggplot(n) returns a blank plot.

library(ggplot2)
library(network)
library(sna)
library(ggnetwork)
n <- network(rgraph(10, tprob = 0.2), directed = FALSE)

n %v% "family" <- sample(letters[1:3], 10, replace = TRUE)
n %v% "importance" <- sample(1:3, 10, replace = TRUE)

e <- network.edgecount(n)
set.edge.attribute(n, "type", sample(letters[24:26], e, replace = TRUE))
set.edge.attribute(n, "day", sample(1:3, e, replace = TRUE))

theme_blank

ggnetwork(n, layout = "fruchtermanreingold", cell.jitter = 0.75)
ggnetwork(n, layout = "target", niter = 100)

ggplot(n)
briatte commented 1 year ago

Hi @Fred-White94 — The tutorial you mention shows you how to use geom_edges and geom_nodes in order to draw the actual graph. On its own, ggnetwork will show neither.