ggnetwork
ggnetwork copied to clipboard
Error with using igraph object as input to ggnetwork
Brief description of the problem
I am trying to create a network plot using an igraph
object and feeding it to ggnetwork
but getting the following error:
Error in igraph::layout_(model, layout, ...) :
all(sapply(modifiers, inherits, what = "igraph_layout_modifier")) is not TRUE
Reproducible example:
library(igraph)
library(GeneNetworkBuilder)
library(ggnetwork)
data("ce.miRNA.map")
data("example.data")
data("ce.interactionmap")
data("ce.IDsMap")
sifNetwork<-buildNetwork(example.data$ce.bind, ce.interactionmap, level=2)
cifNetwork<-filterNetwork(rootgene=ce.IDsMap["DAF-16"], sifNetwork=sifNetwork,
exprsData=uniqueExprsData(example.data$ce.exprData, "Max", condenseName='logFC'),
mergeBy="symbols",
miRNAlist=as.character(ce.miRNA.map[ , 1]), tolerance=1)
gR<-polishNetwork(cifNetwork)
tmpNetwork <- igraph.from.graphNEL(gR) # igraph object
p <- ggnetwork(tmpNetwork, layout = "fruchtermanreingold", cell.jitter = 0.75)
Sessioninfo:
> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS High Sierra 10.13.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggnetwork_0.5.8 ggplot2_3.3.0 GeneNetworkBuilder_1.30.0
[4] Rcpp_1.0.4.6 igraph_1.2.5
loaded via a namespace (and not attached):
[1] graph_1.66.0 rstudioapi_0.11 magrittr_1.5 BiocGenerics_0.34.0
[5] tidyselect_1.1.0 munsell_0.5.0 colorspace_1.4-1 rjson_0.2.20
[9] R6_2.4.1 rlang_0.4.6 dplyr_0.8.5 plyr_1.8.6
[13] tools_4.0.0 parallel_4.0.0 grid_4.0.0 gtable_0.3.0
[17] withr_2.2.0 ellipsis_0.3.0 htmltools_0.4.0 assertthat_0.2.1
[21] yaml_2.2.1 digest_0.6.25 tibble_3.0.1 lifecycle_0.2.0
[25] crayon_1.3.4 purrr_0.3.4 Rgraphviz_2.32.0 vctrs_0.3.0
[29] htmlwidgets_1.5.1 glue_1.4.1 pillar_1.4.4 compiler_4.0.0
[33] scales_1.1.1 stats4_4.0.0 XML_3.99-0.3 pkgconfig_2.0.3
Just letting you know that the problem is occurring with igraph v1.2.5 but not with igraph v1.2.4. You can either close this or keep it open, although I have posted this on igraph discourse group: https://igraph.discourse.group/t/error-with-igraph-layout/228
Thanks for the detailed report. Could you try passing "fr"
instead of "fruchtermanreingold"
to the layout
argument? That's how igraph
calls that placement algorithm, so that's how you want to call it.
I had the same problem, and it really seems to be an igraph v1.2.5 bug. Passing "fr"
instead of "fruchtermanreingold"
does not work either.
Thanks @komalsrathi and @almeidasilvaf
Does this work on your end? It should:
ggnetwork::ggnetwork(n, layout = with_fr())
Note that cell.jitter
is not a valid parameter for igraph
's Fruchterman-Reingold layout (anymore?).
This explains the error message.
Hi @briatte. I've tried with_fr()
and it worked. Thank you!
@briatte I haven't tried it but looks like it works thanks @almeidasilvaf for giving it a go.
currently, I have the same problem
Error in igraph::layout_(model, layout, ...) : all(sapply(modifiers, inherits, what = "igraph_layout_modifier")) is not TRUE
So, I changed it to
ggnetwork(infoGW, layout = with_fr())
which gives the following error:
Error in rbind(deparse.level, ...) : numbers of columns of arguments do not match
Not sure if this is related to ggnetwork()
functionality when using an igraph object infoGW
.
infoGW
IGRAPH 818c7d7 UNW- 312 1021 --
+ attr: name (v/c), ens (v/c), weight (v/n), p (v/n), weight (e/n)
+ edges from 818c7d7 (vertex names):
sessionInfo()
R version 4.0.3 (2020-10-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] here_0.1 forcats_0.5.0 stringr_1.4.0 dplyr_1.0.2 purrr_0.3.4 readr_1.4.0
[7] tidyr_1.1.2 tibble_3.0.4 tidyverse_1.3.0 igraph_1.2.6 ggnetwork_0.5.8 ggplot2_3.3.2
[13] intergraph_2.0-2loaded via a namespace (and not attached): [1] network_1.16.1 tidyselect_1.1.0 xfun_0.19 sna_2.6 haven_2.3.1
[6] lattice_0.20-41 rle_0.9.2 colorspace_2.0-0 vctrs_0.3.4 generics_0.1.0
[11] rlang_0.4.8 pillar_1.4.6 glue_1.4.2 withr_2.3.0 DBI_1.1.0
[16] RColorBrewer_1.1-2 dbplyr_2.0.0 modelr_0.1.8 readxl_1.3.1 lifecycle_0.2.0
[21] plyr_1.8.6 munsell_0.5.0 gtable_0.3.0 cellranger_1.1.0 rvest_0.3.6
[26] coda_0.19-4 knitr_1.30 GGally_2.0.0 fansi_0.4.1 broom_0.7.2
[31] Rcpp_1.0.5 scales_1.1.1 backports_1.2.0 jsonlite_1.7.1 fs_1.5.0
[36] hms_0.5.3 stringi_1.5.3 rprojroot_1.3-2 grid_4.0.3 cli_2.1.0
[41] tools_4.0.3 magrittr_1.5 crayon_1.3.4 pkgconfig_2.0.3 ellipsis_0.3.1
[46] xml2_1.3.2 reprex_0.3.0 lubridate_1.7.9 assertthat_0.2.1 reshape_0.8.8
[51] httr_1.4.2 rstudioapi_0.11 statnet.common_4.4.1 R6_2.5.0 compiler_4.0.3
I am wondering if there is any update on this issue?
I just tried with both igraph 1.2.4 and 1.2.5, both of them didn't work.
I also tried layout = with_fr()
, same error message.
sessioninfo:
sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggnetwork_0.5.8 ggplot2_3.3.2 topicmodels_0.2-11 hash_2.2.6.1
[5] quanteda_2.1.1
loaded via a namespace (and not attached):
[1] NLP_0.2-1 Rcpp_1.0.5 pillar_1.4.6 compiler_4.0.2
[5] tools_4.0.2 stopwords_2.0 lifecycle_0.2.0 tibble_3.0.3
[9] gtable_0.3.0 lattice_0.20-41 pkgconfig_2.0.3 rlang_0.4.7
[13] igraph_1.2.4 Matrix_1.2-18 fastmatch_1.1-0 cli_2.0.2
[17] rstudioapi_0.11 parallel_4.0.2 yaml_2.2.1 xfun_0.17
[21] withr_2.3.0 stargazer_5.2.2 knitr_1.30 xml2_1.3.2
[25] dplyr_1.0.2 generics_0.0.2 vctrs_0.3.4 fs_1.5.0
[29] stats4_4.0.2 grid_4.0.2 tidyselect_1.1.0 glue_1.4.2
[33] data.table_1.13.0 R6_2.4.1 fansi_0.4.1 purrr_0.3.4
[37] magrittr_1.5 modeltools_0.2-23 scales_1.1.1 ellipsis_0.3.1
[41] usethis_1.6.3 assertthat_0.2.1 colorspace_1.4-1 stringi_1.5.3
[45] RcppParallel_5.0.2 munsell_0.5.0 tm_0.7-7 slam_0.1-47
[49] crayon_1.3.4
Hi @peranti and @justinchuntingho
Apologies for the slow reply. I haven't updated ggnetwork
in a while, and have left your issues unattended because I thought the fix I posted earlier would end up working for you.
Would you mind sharing the actual network objects that you are trying to plot? The following works fine with ggnetwork
and igraph
v1.2.6, which is the current CRAN version:
library(ggnetwork)
n <- igraph::erdos.renyi.game(1000, 1/1000)
head(ggnetwork(n, layout = igraph::with_fr()))
I am therefore thinking that the issue might occur only for specific igraph
objects, but I have to see some of those objects to diagnose that. Thanks in advance!
Hi, @briatte
FYI, using layout = igraph::with_fr()
works fine for me. I am using igraph version 1.2.6 and ggnetwork version 0.5.8 with R version 4.1 (under development).
Perhaps the problem @peranti and @justinchuntingho are facing is related to their R versions or some dependency. For instance, I've noticed that @justinchuntingho did not load the intergraph package. Updating ggplot2 might also help. I'm using ggplot2 version 3.3.3.
I was able to get this working:
library(igraph)
library(GeneNetworkBuilder)
library(ggnetwork)
data("ce.miRNA.map")
data("example.data")
data("ce.interactionmap")
data("ce.IDsMap")
sifNetwork<-buildNetwork(example.data$ce.bind, ce.interactionmap, level=2)
cifNetwork<-filterNetwork(rootgene=ce.IDsMap["DAF-16"], sifNetwork=sifNetwork,
exprsData=uniqueExprsData(example.data$ce.exprData, "Max", condenseName='logFC'),
mergeBy="symbols",
miRNAlist=as.character(ce.miRNA.map[ , 1]), tolerance=1)
gR<-polishNetwork(cifNetwork)
tmpNetwork <- igraph.from.graphNEL(gR) # igraph object
p <- ggnetwork(tmpNetwork, layout = "fruchtermanreingold", cell.jitter = 0.75)
SessionInfo:
> sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS High Sierra 10.13.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] sna_2.6 network_1.16.1 statnet.common_4.4.1 ggnetwork_0.5.1
[5] ggplot2_3.3.3 GeneNetworkBuilder_1.32.0 Rcpp_1.0.6 igraph_1.2.6
loaded via a namespace (and not attached):
[1] compiler_4.0.4 pillar_1.5.0 plyr_1.8.6 tools_4.0.4 digest_0.6.27
[6] lattice_0.20-41 rle_0.9.2 lifecycle_1.0.0 tibble_3.1.0 gtable_0.3.0
[11] debugme_1.1.0 pkgconfig_2.0.3 rlang_0.4.10 graph_1.68.0 DBI_1.1.1
[16] Rgraphviz_2.34.0 ggrepel_0.9.1 parallel_4.0.4 xfun_0.21 coda_0.19-4
[21] withr_2.4.1 dplyr_1.0.4 generics_0.1.0 htmlwidgets_1.5.3 vctrs_0.3.6
[26] stats4_4.0.4 grid_4.0.4 tidyselect_1.1.0 glue_1.4.2 R6_2.5.0
[31] fansi_0.4.2 XML_3.99-0.5 purrr_0.3.4 magrittr_2.0.1 scales_1.1.1
[36] htmltools_0.5.1.1 ellipsis_0.3.1 BiocGenerics_0.36.0 assertthat_0.2.1 colorspace_2.0-0
[41] intergraph_2.0-2 tinytex_0.29 utf8_1.1.4 munsell_0.5.0 crayon_1.4.1
[46] rjson_0.2.20
@almeidasilvaf Many thanks for your message, that's encouraging!
@komalsrathi That's also good news, thanks. It's strange, however, because if I remember correctly, "fruchtermanreingold"
is how the layout algorithm is called for objects of class network
, not igraph
, and I cannot find the string in how igraph
handles layouts.
This is the plot I get after running the code below so I am guessing it is working as expected?:
library(igraph)
library(GeneNetworkBuilder)
library(ggnetwork)
data("ce.miRNA.map")
data("example.data")
data("ce.interactionmap")
data("ce.IDsMap")
sifNetwork<-buildNetwork(example.data$ce.bind, ce.interactionmap, level=2)
cifNetwork<-filterNetwork(rootgene=ce.IDsMap["DAF-16"], sifNetwork=sifNetwork,
exprsData=uniqueExprsData(example.data$ce.exprData, "Max", condenseName='logFC'),
mergeBy="symbols",
miRNAlist=as.character(ce.miRNA.map[ , 1]), tolerance=1)
gR<-polishNetwork(cifNetwork)
tmpNetwork <- igraph.from.graphNEL(gR) # igraph object
p <- ggnetwork(tmpNetwork, layout = "fruchtermanreingold", cell.jitter = 0.75)
tmpNetwork <- ggnetwork(tmpNetwork, layout = "fruchtermanreingold", cell.jitter = 0.75)
nodeSize <- data.frame(table(tmpNetwork$vertex.names))
tmpNetwork <- tmpNetwork %>%
inner_join(nodeSize, by = c("vertex.names" = "Var1")) %>%
dplyr::rename("Frequency" = "Freq")
p <- ggplot(tmpNetwork, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges(color = "grey50")+
geom_nodelabel(aes(label = vertex.names, color = Frequency), fontface = "bold")+
theme_blank() +
scale_color_continuous(low = "grey", high = "red")
@komalsrathi Thanks! Looks legit, at least from a graphical perspective.
However, your codes does fail with ggnetwork
0.5.8 (you are using v0.5.1). That's because we added support for igraph
layouts, and that led to changes that currently makes it impossible to pass a network
layout (such as fruchtermanreingold
) on an igraph
object (like yours), or vice versa.
With the most recent version of ggnetwork
, your code should read as follows to work:
p <- ggnetwork(tmpNetwork, layout = igraph::with_fr())
This still uses the FR algorithm, although it uses the igraph
version, which does not have a cell.jitter
argument (and might also be different from the one used by network
in other ways).
This thread is making me think that the next package update should make it possible to mix network
and igraph
layouts and network objects. This is what #59 also asks for.
I cannot recall but there was an issue downstream (when I wanted to plot the network) and which is why why I might have decided to downgrade to v0.5.1. What you are suggesting makes sense.
Hi @briatte, Though I am using the latest version, I still encounter the issue. Please find my session information below.
Did anyone overcome the issue? Kindly share your work-around.
> is_igraph(net)
[1] TRUE
> ggnetwork(net, layout = igraph::with_fr())
Error in rbind(deparse.level, ...) :
numbers of columns of arguments do not match
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] igraph_1.2.6 ggnetwork_0.5.10 ggplot2_3.3.5
loaded via a namespace (and not attached):
[1] magrittr_2.0.1 tidyselect_1.1.1 munsell_0.5.0 lattice_0.20-44 colorspace_2.0-2 R6_2.5.1
[7] rlang_0.4.11 fansi_0.5.0 dplyr_1.0.7 tools_4.1.0 grid_4.1.0 gtable_0.3.0
[13] utf8_1.2.2 DBI_1.1.1 withr_2.4.2 ellipsis_0.3.2 assertthat_0.2.1 tibble_3.1.4
[19] lifecycle_1.0.0 crayon_1.4.1 Matrix_1.3-4 purrr_0.3.4 vctrs_0.3.8 glue_1.4.2
[25] compiler_4.1.0 pillar_1.6.2 generics_0.1.0 scales_1.1.1 pkgconfig_2.0.3
However, the below example provided by you (@briatte ) works. So, the issue may be with my "igraph object" net
? Any suggestions on how to dissect the issue?
> n <- igraph::erdos.renyi.game(1000, 1/1000)
> is_igraph(n)
[1] TRUE
> head(ggnetwork(n, layout = igraph::with_fr()))
x y xend yend
2 0.006968701 0.4046888 0.01824830 0.3866026
5 0.013422112 0.5220388 0.00955488 0.5071942
6 0.013593759 0.5511242 0.01097742 0.5673587
7 0.014594464 0.4604295 0.01847037 0.4764745
8 0.014594464 0.4604295 0.00000000 0.4670571
11 0.018871086 0.5951092 0.03224330 0.5850051