I would like create an interactive enrichment map. I have used the emapplot
function from the enrichplot package to do this. But this function returns a static plot. I would like to make it interactive using (preferably) the visNetwork package.
The emapplot
function returns a ggraph object. I couldn't find a function to change the ggraph object into a igraph/visNetwork/tbl_graph object. So then I thought about extracting the node and edge information.
This can be used to create an example ggraph object.
library(igraph)
library(ggraph)
library(tidyverse)
graph <- graph_from_data_frame(highschool)
graph2 <- ggraph(graph, layout = "kk") +
geom_edge_link(aes(colour = factor(year))) +
geom_node_point()
attributes(graph2)
Output:
$names
[1] "data" "layers" "scales" "mapping" "theme" "coordinates" "facet" "plot_env" "labels"
$class
[1] "ggraph" "gg" "ggplot"
Node positions can be obtained using graph2$data
.
x y name .ggraph.orig_index circular .ggraph.index
1 0.7326425 2.3767052 1 1 FALSE 1
2 0.7041666 2.9986454 2 2 FALSE 2
3 1.5125110 2.9624914 3 3 FALSE 3
4 -2.7467842 -1.0804763 4 4 FALSE 4
5 -2.8196405 0.2369667 5 5 FALSE 5
6 -2.6184244 2.1968979 6 6 FALSE 6
Now I need to know now to get the edge information.
I saw ggraph::get_edges
is used by functions like geom_edge_link
to retrieve edge information. I couldn't get this to work unfortunately.
Does someone know how to get edge information from a ggraph object, or change it into an igraph object?
Edit
On request of camille, here is an example using the emapplot function.
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("enrichplot")
library(DOSE)
library(ggnewscale)
library(ggraph)
library(igraph)
library(enrichplot)
data(geneList)
de <- names(geneList)[1:100]
x <- enrichDO(de)
x2 <- pairwise_termsim(x)
graph <- emapplot(x2)