在R中设置一个新的调色板():需要调用两次调色板(rainbow(N))

时间:2015-05-31 07:31:47

标签: r

我在一个循环中绘制绘图,每个绘图都需要一个新的调色板,根据绘图中的元素数量。

我对调色板(彩虹(i))没有立竿见影的事实感到困惑。相反,我必须把它叫两次。

例如,这不起作用:

for(i in 10:20){
    colors <- palette(rainbow(i))
    if (i !=length(colors)){cat("\nNumber of colors does not match", 
                                i,"-",  length(colors))}
}

Number of colors does not match 10 - 20
Number of colors does not match 11 - 10
Number of colors does not match 12 - 11
Number of colors does not match 13 - 12
Number of colors does not match 14 - 13
Number of colors does not match 15 - 14
Number of colors does not match 16 - 15
Number of colors does not match 17 - 16
Number of colors does not match 18 - 17
Number of colors does not match 19 - 18
Number of colors does not match 20 - 19

为了确保设置新调色板,我必须调用它两次:

for(i in 10:20){
    colors <- palette(rainbow(i))
    colors <- palette(rainbow(i))
    if (i !=length(colors)){cat("\nNumber of colors does un match", 
                                 i,"-",  length(colors))}
}

这是一些错误还是我以错误的方式使用调色板?

0 个答案:

没有答案