如何在R中设置更多颜色?

问题描述 投票:1回答:1

我想在R中用21种颜色为我的图形着色,所以我设置了21种颜色:

palette(c(rgb(171,182,62,maxColorValue=255),rgb(158,88,203,maxColorValue=255),
          [...]                    

但是当我使用这个命令时:

scatter3d(x = red, y = green, z = blue, groups = C1class$V1, grid = FALSE, surface = FALSE)

它给我一个错误:

Error in scatter3d.default(x = red, y = green, z = blue, groups = C1class$V1,  : 
  Number of groups (13) exceeds number of colors (8)

如何设置新的调色板以着色图形?

r colors
1个回答
1
投票

car::scatter3d()函数默认忽略调色板。如果您想使用9色调色板,可以在通话中设置surface.col=1:9。修改lukeA的答案,

library(car)            
d <- Duncan
d$type <- as.factor(sample(1:9, nrow(d), TRUE))
palette(rainbow(9)) # Or use your own palette...
scatter3d(prestige ~ income + education | type, data = d, surface.col = 1:9, grid = FALSE, 
          surface = FALSE)
© www.soinside.com 2019 - 2024. All rights reserved.