我上周发布了这个帖子,但我没有正确解释,我希望你们中的一些人能帮助我......
我试图将多层同心环绘制为图形的顶点。
在这里,您可以找到我did的简单版本,以及我want to do的内容。请注意,边缘也应该用顶点拖动。
这是前者的代码:
library(igraph)
g=graph.empty(4)
g[1,2]=T
g[3,4]=T
resColors=matrix(as.character(list("green","red","green","green","green","grey","grey", "green","green","green","red","red","green","green","green","green","red","red","green","green")), nrow=vcount(g))
colors = list()
values = list()
for (i in 1:vcount(g)) {
values[[i]] = rep(1, times = ncol(resColors))
colors[i] = list(resColors[i,])
}
size=c(60,50,30,20)
plot(g, vertex.shape = "pie", vertex.pie = values, vertex.pie.color = colors, vertex.size = size)
谢谢,Nat
答案 0 :(得分:0)
这可能会让你从基础R开始。如果你想让箭头触及饼图,你需要更多地使用布局和箭头。
par(mar=c(1,1,1,1));
layout(matrix(c(0,0,0,0,0,0,0,
0,0,0,0,0,0,0,
1,1,1,1,6,6,0,
1,2,2,5,5,6,0,
1,2,2,1,0,0,0,
1,1,1,3,0,0,0,
0,0,0,0,3,0,0,
0,0,0,0,0,3,4,
0,0,0,0,0,4,4), nrow=9, byrow=TRUE));
pie(x=c(0.4,0.3,0.2,0.1), labels = NA);
pie(x=c(0.4,0.3,0.2,0.1), labels = NA);
plot(x=1, y=1, type='n', axes = FALSE, xlim = c(0,100), ylim = c(0,100))
arrows(x0=0, y0=100, x1 = 80, y1 = 20, length=0.25)
pie(x=c(0.4,0.3,0.2,0.1), labels = NA);
plot(x=1, y=1, type='n', axes = FALSE, xlim = c(0,100), ylim = c(0,100))
arrows(x0=0, y0=0, x1 = 80, y1 = 90)
pie(x=c(0.4,0.3,0.2,0.1), labels = NA);
或者,也许有一种方法可以混合和匹配来自不同包的图和图像,在这种情况下可以提供帮助。见这里:Combine base and ggplot graphics in R figure window
编辑:
如果您只使用一个plot
语句,而不是上面示例中的两个语句,并使用该一个隐形图填充整个layout
,那么您可以添加arrows
个你要。重要的是,你可能会通过你给每个箭头的x和y坐标非常精细地控制那些arrows
的位置。您可以在一个pie
上添加plot
图表,并且可能会arrows
触及pie
图表而不会遇到麻烦。
答案 1 :(得分:0)
解决方案比我简单,以防其他人需要答案:
在绘图之前,你打电话给布局,以fruchterman.reingold为例:
lay <- layout.fruchterman.reingold(g)
然后编辑lay,在示例中,您想要节点1上的节点3:
lay[3,] <- lay[1,]
最后,您使用已编辑的布局进行绘图:
plot(g, vertex.shape = "pie", vertex.pie = values, vertex.pie.color = colors,
vertex.size = size, layout = lay)