简体   繁体   中英

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. I was wondering if there would be a way to plot a 4th dimension by controlling the size of spheres.

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. Can the same result be achieved using 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):

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)

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

在此处输入图片说明

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