首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RGL Plot3D:更多颜色,无重复

RGL Plot3D:更多颜色,无重复
EN

Stack Overflow用户
提问于 2015-04-03 23:55:50
回答 1查看 750关注 0票数 1

在使用rgl plot3D绘图时,我使用的内容如下:

代码语言:javascript
复制
col = as.integer(as.factor(data[[input$colorBy]])))
plot3d(d[,1], d[,2], d[,3], type=type, col=col, add=TRUE)

然而,如果有超过10个不同的因素,这将重复颜色。有没有办法扩展这一点,使颜色永远不会重复,并且(理想情况下)颜色跨越色彩空间的很大范围?

EN

回答 1

Stack Overflow用户

发布于 2015-04-04 01:23:13

有许多方法可以自己设置颜色。我在下面的示例中使用了z值来设置颜色,但您当然可以使用分组变量、转换等来设置颜色。以下是一些选项:

代码语言:javascript
复制
# 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))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29435537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档