Reputation: 177
Hey I want to create my own custom palette of color in R using the brewer.pal() function. And then I want to view it using the image function.
ny<-brewer.pal(7,"Blues")
image(x=1:7,y=1,z=as.matrix(1:7),col=ny)
This code gives 7 shdes of blue, however i want to give my own choice of 7 different colors.
image(x=1:7,y=1,z=as.matrix(1:7),col=c("Reds","Blues"))
I thought of trying this function, but its obvious wrong. Can someone please help me. I specifically want to use the brewer.pal() and image() funcions
Upvotes: 2
Views: 545
Reputation: 1189
If you'd prefer a gradient between 2+ colors of your choosing, you could also use colorRampPalette
pretty = colorRampPalette(c('#EF6780', '#80ef67', '#6780ef'))
image(x=1:7,y=1,z=as.matrix(1:7),col=pretty(200))
Upvotes: 2
Reputation: 4907
You can specify colors as hexadecimal colors in R. For example
image(x=1:7,y=1,z=as.matrix(1:7),col= "#CC6666")
References:
http://www.color-hex.com/
http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/
Upvotes: 1