简体   繁体   English

RGB 3D散点图-从第4维控制球体的大小(气泡图)

[英]rgl 3D scatterplot - controlling size of spheres from 4th dimension (bubble plot)

I am working on a 3D scatter plot using rgl package in R, with multiple colors for different series. 我正在使用R中的rgl包来制作3D散点图,其中不同系列使用多种颜色。 I was wondering if there would be a way to plot a 4th dimension by controlling the size of spheres. 我想知道是否可以通过控制球体的大小来绘制第4维。

I know it's possible with plotly ("bubble plot") : https://plot.ly/r/3d-scatter-plots/ , but Plotly starts to flicker when dealing with lots of datapoints. 我知道有可能使用plotly(“气泡图”): https ://plot.ly/r/3d-scatter-plots/,但是当处理大量数据点时,Plotly开始闪烁。 Can the same result be achieved using Rgl? 使用Rgl可以达到相同的结果吗?

set.seed(101)
dd <- data.frame(x=rnorm(100),y=rnorm(100),z=rnorm(100),
                 c=rnorm(100),s=rnorm(100))

Scaling function (I tweaked to keep the values strictly in (0,1), don't know if that's really necessary): 缩放功能(我将值严格限制为(0,1),不知道这是否真的必要):

ss <- function(x) scale(x,center=min(x)-0.01,scale=diff(range(x))+0.02)
library(rgl)

Define colours (there may be a better way to do this ...) 定义颜色(可能会有更好的方法...)

cvec <- apply(colorRamp(c("red","blue"))(ss(dd$c))/255,1,
              function(x) rgb(x[1],x[2],x[3]))

The picture (need type="s" to get spheres) 图片(需要type="s"才能获得球体)

with(dd,plot3d(x,y,z,type="s",radius=ss(s), col=cvec))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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