【问题标题】:R : Plotting a Graph - 'x' is a list, but does not have components 'x' and 'y'R:绘制图形 - “x”是一个列表,但没有组件“x”和“y”
【发布时间】:2020-11-23 15:54:36
【问题描述】:

使用 R,我创建了一个图形对象并能够生成一个子图 (make_ego_graph)。 sub_graph 已成功创建,但我无法绘制此图。

我已附上以下代码:

library(igraph)
file <-data.frame(

"source" = c(
    "John",
    "John",
    "Tim",
    "Tim",
    "Alex",
    "Andrew",
    "Andrew",
    "Andrew",
    "Oliver",
    "Oliver",
    "Oliver",
    "Matt",
    "Steven",
    "Steven",
    "Steven",
    "Matt",
    "Charles",
    "Charles",
    "Charles",
    "Sean",
    "Ted",
    "Ryan",
    "Ryan",
    "Ryan",
    "Ted",
    "Phil",
    "Phil",
    "Phil",
    "Sam",
    "Toby",
    "Toby",
    "Donald",
    "Donald",
    "Donald",
    "Mitch",
    "Mitch",
    "Mitch"),

"target" = c("Sam",
             "Tim",
             "Alex",
             "Matt",
             "Andrew",
             "Sean",
             "Peter",
             "Ben",
             "Kevin",
             "Thomas",
             "Dave",
             "Steven",
             "Kenny",
             "Derek",
             "CJ",
             "Charles",
             "Ivan",
             "Kyle",
             "Andrew",
             "Ted",
             "Ryan",
             "Daniel",
             "Chris",
             "Scott",
             "Phil",
             "Henry",
             "George",
             "Paul",
             "Toby",
             "Donald",
             "Mitch",
             "Jack",
             "Luke",
             "Myles",
             "Elliot",
             "Harvey",
             "Owen")

)

从这里,我创建图表:

# create graph
graph <- graph.data.frame(file, directed=F)
graph <- simplify(graph)
plot(graph)

现在,我正在尝试绘制子图:

#create subgraph
ego = make_ego_graph(graph, "John", order = 3)
plot(ego)

Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' is a list, but does not have components 'x' and 'y'

谁能告诉我我做错了什么?

谢谢

【问题讨论】:

    标签: r plot graph data-visualization


    【解决方案1】:

    我想通了:

    ego = make_ego_graph(graph, "John", order = 3)
    a = ego[[1]]
    plot(a)
    

    【讨论】:

      猜你喜欢
      • 2023-02-26
      • 1970-01-01
      • 2016-10-29
      • 2016-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      相关资源
      最近更新 更多