如何保存 igraph 图

Zeu*_*eus 7 r igraph

很棒的 igraph 包,但我正在努力保存这些图。我已经在网上拖网但没有成功。这是一些示例代码,如何保存结果图?

Test <- data.frame(
  FirstName=c("Bob","Charlie","Beth","Sam"),
  Age=c(23,56,41,33))

Friends <- c(1,2,1,4,2,4,3,4)

g <- graph.empty (4, directed = FALSE)
V(g)$color <- "lightblue"  #Nodes$NodeColour
V(g)$label <- as.character(Test$FirstName)
g <- add.edges(g, Friends)
plot(g,
     vertex.label.color="black",
     vertex.shape="sphere",
     vertex.label.cex = 0.5,
     vertex.size=24,
     layout=layout.circle)
title("Friend Network",cex.main=1,col.main="blue")

#how do you save plot as a png?
Run Code Online (Sandbox Code Playgroud)

c0b*_*bra 2

我不喜欢将图表保存为静态图像,而是更喜欢将它们保存为 html 文件并拥有交互式图表:

library(visNetwork)
library(htmlwidgets)
saveWidget(visIgraph(g), file = "test.html")
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅https://datastorm-open.github.io/visNetwork/igraph.html 。