# go from green through yellow to red with no blue
x<-rnorm(20)
y<-rnorm(20)
# use y for the color scale
plot(x,y,col=color.scale(y,c(0,1,1),c(1,1,0),0),main="Color scale plot",
pch=16,cex=2)
plot(1:10,rep(1:3,length.out=10),axes=FALSE,type="n",xlim=c(0,11),ylim=c(0,4),
main="Test of RGB, HSV and HCL",xlab="",ylab="Color specification")
axis(2,at=1:3,labels=c("HCL","HSV","RGB"))
points(1:10,rep(1,10),pch=19,cex=8,col=color.scale(1:10,c(0,300),35,85,
color.spec="hcl"))
points(1:10,rep(2,10),pch=19,cex=8,col=color.scale(1:10,c(0,1),
0.8,1,color.spec="hsv"))
points(1:10,rep(3,10),pch=19,cex=8,col=color.scale(1:10,c(1,0.5,0),
c(0,0.5,0),c(0,0,1),color.spec="rgb"))
if (FALSE) {
# requires viridisLite
library(viridisLite)
plot(0,xlim=c(-1,1),ylim=c(-1,1),type="n",axes=FALSE,
main="Approximating other color scales",xlab="",ylab="")
gradient.rect(-1,0.8,1,0.95,nslices=50,
col=color.scale(1:50,1,
c(0,0.3,0.6,0.8,1,1),
c(0,0,0,0,0,0,1)))
text(0,1,"color.scale")
gradient.rect(-1,0.65,1,0.8,col=heat.colors(50))
text(0,0.6,"heat.colors")
gradient.rect(-1,0.3,1,0.45,nslices=50,
col=color.scale(1:50,c(0,0.2,0.9,0.95,0.95),
c(0.7,0.8,0.9,0.7,0.95),
c(0.1,0,0,0.35,0.95)))
text(0,0.5,"color.scale")
gradient.rect(-1,0.15,1,0.3,col=terrain.colors(50))
text(0,0.1,"terrain.colors")
gradient.rect(-1,-0.2,1,-0.05,nslices=50,
col=color.scale(1:50,c(0.3,0,0.3,0.1,1,0.95,1),
c(0,0.3,0.9,1,1,0.85,0.85),
c(1,1,0.9,0.1,0,0.5,0.5)))
text(0,0,"color.scale")
gradient.rect(-1,-0.35,1,-0.2,col=topo.colors(50))
text(0,-0.4,"topo.colors")
gradient.rect(-1,-0.7,1,-0.55,nslices=50,
col=color.scale(1:50,c(0.3,0.2,0,0.4,0.95),
c(0.1,0.3,0.6,0.75,0.95),
c(0.3,0.6,0.5,0.4,0)))
text(0,-0.5,"color.scale")
gradient.rect(-1,-0.85,1,-0.7,col=viridis(50))
text(0,-0.9,"viridis")
}
Run the code above in your browser using DataLab