使用rgl plot3D进行绘图时,我使用以下内容:
col = as.integer(as.factor(data[[input$colorBy]])))
plot3d(d[,1], d[,2], d[,3], type=type, col=col, add=TRUE)
但是,如果有超过10个左右的不同因素,这将重复颜色。有没有办法扩展它,以便从不重复颜色,并且(理想情况下)颜色跨越大范围的颜色空间?
答案 0 :(得分:1)
您可以通过多种方式自行设置颜色。我已经使用z值来设置下面示例中的颜色,但您当然可以使用分组变量,转换等设置颜色。以下是一些选项:
# Fake data
dat = data.frame(x=sort(runif(100,0,100)), y=runif(100,0,100))
dat$z = dat$x + dat$y
dat = dat[order(dat$z), ]
# hcl colors (I've scaled z so that the h value ("hue") ranges from
# zero to 350 (where the hue scale ranges from 0 to 360 degrees))
plot3d(dat, col=hcl(350*(dat$z - min(dat$z))/(max(dat$z) - min(dat$z)), 100, 65))
# Create a color ramp function (from red to green to blue in this case)
colFunc = colorRamp(c(rgb(1,0,0), rgb(0,1,0), rgb(0,0,1)))
cols=colFunc(dat$z/max(dat$z))
plot3d(dat, col=rgb(cols, maxColorValue=255))