0

I'm using package "networktools" in R (https://cran.r-project.org/web/packages/networktools/networktools.pdf). I've created a three "bridge"-objects: DataT5_SDQ_network_b, DataT6_SDQ_network_b, and DataT7_SDQ_network_b.

I've sucessfully plotted one "bridge"-object using this code:

plot(DataT7_SDQ_network_b, include=c("Bridge Expected Influence (1-step)"), theme_bw=FALSE, zscore=TRUE)

Q: How can I plot all three "bridge"-objects in the same plot (with legend)?

Brage Kraft
  • 45
  • 1
  • 6
  • I can see a way to do this, but it is quite involved and would require you to post a reproducible example. Are you able to provide one? (i.e. the data and code you used to make your bridges) – Allan Cameron May 11 '22 at 08:53
  • 1
    The three bridge-objects are downloadable here: https://drive.google.com/file/d/12Hgq78RjuXXRLplIXJw6SNU4NoZbULcc/view?usp=sharing The code which generates a bridge-object (using networktools): `DataT5_SDQ_network_b <- bridge(DataT5_SDQ_network, communities=SDQ_communitiesSG, directed=FALSE, nodes = DataT5_SDQ_list$names)` – Brage Kraft May 11 '22 at 09:25

1 Answers1

0

I don't think there's a way to do this inside networktools, but since the plot generic returns a ggplot object, we can harvest multiple plots and combine them with a legend like this:

p <- lapply(list(DataT5_SDQ_network_b,
                 DataT6_SDQ_network_b,
                 DataT7_SDQ_network_b), function(x) suppressWarnings(plot(x)))

p <- Map(function(a, b) { a$data$Class <- b; a}, a = p, b = c("T5", "T6", "T7"))

p[[1]]$data <- do.call(rbind, lapply(p, function(x) x$data))

p <- p[[1]] + aes(color = Class, group = Class)

p

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • Beautiful! 1. How can I get the plot only showing Bridge Expected Influence? 2. How can I show the data as z-scores? – Brage Kraft May 11 '22 at 13:04