2017-09-25 28 views
0

比方說,我產生這個圖表:檢索節點從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

一個將如何檢索該圖表節點的X和Y座標?

回答

1

使用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

您可以使用一些從IGRAPH layout_功能包。他們返回一個具有頂點座標的矩陣。