cannot coerce class ‘“igraph“’ to a data.frame

报错代码:

ggraph(g, "manual", x = V(g)$x, y = V(g)$y) +
  geom_edge_link0() +
  geom_scatterpie(
    cols = c("A", "B", "C"),
    data = as_data_frame(g, "vertices"),  #这一行
    colour = NA,
    pie_scale = 2
  ) +
  coord_fixed() +
  theme_graph() +
  theme(legend.position = "bottom")

报错信息:

Error in as.data.frame.default(value, stringsAsFactors = FALSE) : 
  cannot coerce class ‘"igraph"’ to a data.frame

解决方案:

ggraph(g, "manual", x = V(g)$x, y = V(g)$y) +
  geom_edge_link0() +
  geom_scatterpie(
    cols = c("A", "B", "C"),
    data = igraph::as_data_frame(g, "vertices"), #添加igraph::
    colour = NA,
    pie_scale = 2
  ) +
  coord_fixed() +
  theme_graph() +
  theme(legend.position = "bottom")

参考链接:https://lists.nongnu.org/archive/html/igraph-help/2018-02/msg00019.html


版权声明:本文为weixin_40640700原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。