2017-09-25 5 views
0

Disons que je produis ce tableau:noeud Récupération coordonnées de carte réseau GGRAPH

library(ggraph) 
library(igraph) 

my_chart <- graph_from_data_frame(highschool) 
set.seed(2017) 

ggraph(my_chart, layout = "nicely") + geom_edge_link() + geom_node_point() 

enter image description here

Comment peut-on récupérer les coordonnées x et y des noeuds de ce tableau?

Répondre

1

En utilisant ggplot_build

library(ggraph) 
library(igraph) 

my_chart <- graph_from_data_frame(highschool) 
set.seed(2017) 

p <- ggraph(my_chart, layout = "nicely") + geom_edge_link() + geom_node_point() 

pg <- ggplot_build(p) 

lines are in pg[[1]][[1]] 

ggplot(data= pg[[1]][[1]])+ 
    geom_line(aes(x=x,y=y, group=group), size = 0.1) 

enter image description here

while points are in pg[[1]][[2]]

ggplot(data= pg[[1]][[1]])+ 
    geom_line(aes(x=x,y=y, group=group), size = 0.1)+ 
    geom_point(data= pg[[1]][[2]], aes(x=x,y=y, group=group), color = "red") 

enter image description here

0

Vous pourriez utiliser certaines fonctions de layout_ igraph paquet. Ils renvoient une matrice avec des coordonnées de vertex.