【问题标题】:How to rotate a plotted igraph, given a specific layout (r code)?给定特定布局(r代码),如何旋转绘制的igraph?
【发布时间】:2021-03-01 13:46:31
【问题描述】:

我有以下代码:

require(igraph)
g = make_star(8, mode="undirected", center=1)
layout.old = layout_with_fr(g, dim=3)
plot(g, layout = layout.old)

我想绘制相同的图表,但对于任何 a w.r.t.原始布局,w.r.t.一个固定的轴,不管它是什么。这个想法是构建一个逐步的动画,所以我需要为每一步绘制一个新的图表(使用函数'plot')(每一步都给出相同的图表,但旋转)。

怎么做?

提前非常感谢!

【问题讨论】:

    标签: r plot rotation igraph


    【解决方案1】:

    您可以使用rgl::rotate3d 函数来实现。例如旋转 在(x,y,z) = (1,1,1) 方向上绕轴旋转 10、20、...、100 度使用

    for (a in 10*(1:10)) {
       plot(g, layout = rgl::rotate3d(layout.old, a*pi/180, x=1,y=1,z=1))
       Sys.sleep(1)
    }
      
    

    您也可以使用rglplot(g, layout = layout.old) 进行交互式绘图。

    【讨论】:

    • 谢谢,我不幸在 rotate3d.default(layout.old, a * pi/180, x = 1, y = 1, z = 1) 中得到错误错误:不支持旋转对象怎么会你修好了吗?
    • 当我运行你的代码和我的代码时,我没有收到任何错误,所以我不知道你出了什么问题。
    • 也许你没有使用dim = 3
    猜你喜欢
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    • 2017-04-17
    • 1970-01-01
    相关资源
    最近更新 更多