带有 R 和 Rgl 的彩色球体的 3d 散点图
我想创建一个球体的 3D 散点图,其颜色为第四维。 我有一个 csv 文件中的数据,其中每行表示粒子的 x、y、z 位置,并且有一列告诉我粒子的值(1,2 或 3)。如果球的值为 1,我想将其着色为一种颜色,否则为另一种颜色。
编辑:
我创建了以下代码:
library(rgl)
m <- read.csv(file="mem0.csv", sep = ",", head=TRUE)
mcol = m$val
i = 1
mdim = dim(m)
while (i <= mdim[1] ){
if (mcol[i] == 1){
mcol[i] = "red"
}else {
mcol[i] = "blue"
}
i = i +1
}
plot3d(m$x, m$y, m$z, col = mcol, type='s', size=0.1)
编辑编号 2:
我使用 rgl.snapshot() 导出到 svg 文件:
数据应该再次显示一层红球、4 层蓝球和一层红球。
I want to create a 3d scatter plot of spheres with their color being the fourth dimension.
I have the data in a csv file where each line indicates the x,y,z position of a particle and I have a column which tells me the value of the particle (1,2 or 3). I want to color the balls in one color if their value is 1 or in another color otherwise.
Edit:
I created the following code:
library(rgl)
m <- read.csv(file="mem0.csv", sep = ",", head=TRUE)
mcol = m$val
i = 1
mdim = dim(m)
while (i <= mdim[1] ){
if (mcol[i] == 1){
mcol[i] = "red"
}else {
mcol[i] = "blue"
}
i = i +1
}
plot3d(m$x, m$y, m$z, col = mcol, type='s', size=0.1)
Edit number 2:
I use the rgl.snapshot() to export to an svg file:
The data should display a layer of red balls, 4 layers of blue balls and a layer of red balls again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
rgl 包的plot3d()函数可以很容易地完成这样的事情。你甚至可以交互式地探索你的情节:
你可以像这样调用
plot3d()
:这会给你类似的东西:
The
plot3d()
function of thergl
package allows to do such a thing quite easily. And you can even explore your plot interactively :You can call
plot3d()
like this :Which will give you something like :