2013-02-05 77 views
1

我怎么能弯曲默认彩虹R.例如,看看这个代码和图像它产生:翘曲R中的彩虹

x = seq(0,50,by=0.005) 
y = runif(length(x),2,5) 
colors = rainbow(length(x)) 
plot(x,y,cex=0.2,pch=16,col=colors) 

enter image description here

我想改变这种所以没有那么多绿色。应该有像黄色,青色和蓝色一样多的绿色。我也想去除洋红色(最右边的“红色”颜色)。我怎么能这样做呢?

回答

8

如果跳过绿色明确了选项产生的,你接近你想要什么,我认为:

par(mfrow=c(2,1)) 
par(mar=c(2,1,3,1)) 

x = seq(0,50,by=0.005) 
y = runif(length(x),2,5) 
colors = rainbow(length(x)) 
plot(x,y,cex=0.2,pch=16,col=colors) 
title(main="old") 

crp.rg <- colorRampPalette(c("red","yellow","cyan","blue","red")) 
colors = crp.rg(length(x)) 
plot(x,y,cex=0.2,pch=16,col=colors) 
title(main="new") 

enter image description here

编辑

你也可以手动编辑每个色彩过渡使它们具有不同的长度:

par(mfrow=c(2,1)) 
par(mar=c(2,1,3,1)) 

x = seq(0,50,by=0.005) 
y = runif(length(x),2,5) 
colors = rainbow(length(x)) 
plot(x,y,cex=0.2,pch=16,col=colors) 
title(main="old") 


crp.step1 <- colorRampPalette(c("red","yellow")) 
crp.step2 <- colorRampPalette(c("yellow","green")) 
crp.step3 <- colorRampPalette(c("green","cyan")) 
crp.step4 <- colorRampPalette(c("cyan","blue")) 
crp.step5 <- colorRampPalette(c("blue","red")) 

colors <- c(
      crp.step1(2666), 
      crp.step2(1000), 
      crp.step3(1000), 
      crp.step4(2666), 
      crp.step5(2667) 
     ) 

plot(x,y,cex=0.2,pch=16,col=colors) 
title(main="new") 

enter image description here

+0

好主意......但现在没有绿色......我仍然想要绿色。 – CodeGuy

+0

@CodeGuy - 看到编辑 - 不是很整洁,但应该允许更多的灵活性。 – thelatemail