本文介绍了R中的3D绘图-使用颜色的第4维的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用plot3d函数在我的R脚本中绘制3d图.我想添加一个第四维,它将是彩色的.我该怎么办?
I am using the plot3d function to make a 3d plot in my R script. I'd like to add a 4th dimension, which will be color. How can I do this?
具体来说,假设我有以下代码:
Specifically, assume I have the following code:
plot3d(x, y, z, col=cols, size=2, type='s')
如何根据作为第4维的值向量填充cols
.
how would I populate cols
based on a vector of values acting as my 4th dimension.
推荐答案
只需创建一个颜色图,然后使用c变量的剪切版本对其进行索引:
Just make a colormap, and then index into it with a cut version of your c variable:
x = rnorm(100)
y = rnorm(100)
z = rnorm(100)
c = z
c = cut(c, breaks=64)
cols = rainbow(64)[as.numeric(c)]
plot3d(x,y,z,col=cols)
这篇关于R中的3D绘图-使用颜色的第4维的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!