I can get thanks to the function RCy3::getNodePosition() x and y coordinates from a graph plot drawn with RCy3 on Cytoscape. Then, I can use ggraph with layout based on the dataframe prepared from coordinates. I have got a graph but with a deeply different structure from the previous one. What could explain this difference?
Consider the following example coming from: http://cytoscape.org/RCy3/articles/Network-functions-and-visualization.html
'''
library(RCy3)
library(ggraph)
'''
'''
lesmis <- system.file("extdata","lesmis.txt", package="RCy3")
dataSet <- read.table(lesmis, header = FALSE, sep = "\t")
'''
Create a graph. Use simplify to ensure that there are no duplicated edges or self loops
'''
gD <- igraph::simplify(igraph::graph.data.frame(dataSet, directed=FALSE))
'''
Verify the number of nodes (77) and edges (254):
'''
igraph::vcount(gD)
igraph::ecount(gD)
'''
create the graph gD on Cytoscape '''
createNetworkFromIgraph(gD,new.title='Les Miserables')
'''
create a graph using ggraph
'''
ggraph(gD, layout = 'kk') +
geom_edge_link(color = "orange", width=0.7) +
geom_node_point(size=5, color="gray50")+
geom_node_text(aes(label = vlabels_1), size=2, color="gray50", repel=T) +
theme_void()
'''
It is qualitatively the same graph obtained by ggraph as on Cytoscape by using RCy3::createNetworkFromIgraph()
Then, we can get coordinates from graph on Cytoscape as following:
'''
mygraph_Miserables <- createIgraphFromNetwork()
mylayout_Miserables <- getNodePosition()
mylayout_Miserables$x_location <- as.numeric(as.character(mylayout_Miserables$x_location))
mylayout_Miserables$y_location <- as.numeric(as.character(mylayout_Miserables$y_location))
colnames(mylayout_Miserables) <- c('x','y')
vlabels_1 <- get.vertex.attribute(gD, "name")
color_labels_1 <- getNodeColor(vlabels_1)
ggraph(mygraph_Miserables, layout = mylayout_Miserables) +
geom_edge_link(color = "orange", width=0.7) +
geom_node_point(size=5, color="gray50") +
geom_node_text(aes(label = vlabels_1), size=2, color="gray50", repel=T) +
theme_void()
'''
This new graph obtained by ggraph using layout = mylayout_Miserables doesn't provide the same structure of the graph provide directly by ggraph or by RCy3. How can we explain that?
Alain Paris