如何使用plotly为r绘制多个网络图?

时间:2017-04-12 17:51:14

标签: r graphics plotly

我想拥有一张带有我所有网络图形的图像,并尝试在plotly中使用subplot函数,但它会弄乱图形。以下是一般示例,以便您了解我的意思:

library(plotly)
library(igraph)
library(igraphdata)

data(karate)
G <- upgrade_graph(karate)
L <- layout.circle(G)
vs <- V(G)
es <- as.data.frame(get.edgelist(G))

Nv <- length(vs)
Ne <- length(es[1]$V1)
Xn <- L[,1]
Yn <- L[,2]

network <- plot_ly(x = ~Xn, y = ~Yn, mode = "markers", text = vs$label, 
hoverinfo = "text")
edge_shapes <- list()
for(i in 1:Ne) {
  v0 <- es[i,]$V1
  v1 <- es[i,]$V2

  edge_shape = list(
    type = "line",
    line = list(color = "#030303", width = 0.3),
    x0 = Xn[v0],
    y0 = Yn[v0],
    x1 = Xn[v1],
    y1 = Yn[v1]
  )

  edge_shapes[[i]] <- edge_shape
}
axis <- list(title = "", showgrid = FALSE, showticklabels = FALSE, zeroline 
= FALSE)

p <- layout(
  network,
  title = 'Karate Network',
  shapes = edge_shapes,
  xaxis = axis,
  yaxis = axis
)

p2 <- layout(
  network,
  title = 'Karate Network',
  shapes = edge_shapes,
  xaxis = axis,
  yaxis = axis
)

p3 <- layout(
  network,
  title = 'Karate Network',
  shapes = edge_shapes,
  xaxis = axis,
  yaxis = axis
)

subplot(p, p2, p3)

最终看起来像这样:

Teste

有谁能解决这个问题?或者,如果subplot函数确实不能与网络图形一起使用,我可以使用哪种方法将这种类型的图形合并在一起?谢谢!

0 个答案:

没有答案