如何使用plotly for r生成多个网络图的子图?
我希望所有网络图形都有一个图像,我尝试在plotly中使用如何使用plotly for r生成多个网络图的子图?,r,graphics,plotly,R,Graphics,Plotly,我希望所有网络图形都有一个图像,我尝试在plotly中使用子绘图功能,但它会弄乱图形。下面是一个通用示例,您可以了解我的意思: 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 <- l
子绘图
功能,但它会弄乱图形。下面是一个通用示例,您可以了解我的意思:
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)
library(plotly)
图书馆(igraph)
图书馆(igraphdata)
数据(空手道)
G