【发布时间】:2016-05-10 15:44:40
【问题描述】:
我在从每一行数据框生成 .png 时遇到了一些麻烦。
基本上,我想rbinddf 到coordinate_sys 的每一行。
对于df和coordinate_sys的每一行,应该生成一个坐标系和一个单位向量“J”,就像this中一样
最后,在为每个 unit_vector 生成一个 .png 文件后,我想制作 .gif 动画。
这是我的脚本的可重现代码;
library(matlib)
library(rgl)
set.seed(12)
x <- runif(10,-0.14,0.1)
y <- runif(10,-0.14,0.1)
z <-sort(runif(10,-0.9,0.9),decreasing=TRUE)
df <- data.frame(x,y,z)
rot <- function(df,out){
coordinate_sys <- rbind(c(1,0,0),c(0,-1,0),c(0,0,1))
vec <- rbind(coordinate_sys, unlist(df))
rownames(vec) <- c("X", "Y", "Z", "J")
print(vectors3d(vec, col=c(rep("black",3), "red"), lwd=2))
out <- png(file="example%02d.png", width=200, height=200)
dev.off()
}
apply(df, 1,rot,out)
【问题讨论】:
-
投反对票有什么意义?
-
你可以尝试类似this
-
@akrun 您之前的回答很好,但到目前为止不需要轮换。每个图中仅显示一个 J 向量。这就是我真正想要的。在您的回答中,除了旋转角度之外,所有图都相同。
-
是的,这就是我删除它的原因。代码中的一些错误。
-
@akrun 我仍然无法理解您提供的链接该怎么做。我的任务与那里提供的示例大不相同。我正在绑定行并希望为每一行执行函数。该示例正在绘制整个 df。