简体   繁体   中英

3D Plotting in R - Using a 4th dimension of color

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')

how would I populate cols based on a vector of values acting as my 4th dimension.

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)

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM