R Simple Way of Finding Colors for Your Graph

Choosing right colors is one of the most significant factors in drawing a effective graph.

1. You can find sets of colors with different types of color schemes at http://colorbrewer2.org/

2. In R,  A package called, “RColorBrewer”, can help you find a set of colors that matches the theme of your graph. It also has 3 types of palettes, sequential, diverging, and qualitative.

1)  Load the package

library(“RColorBrewer”)

2) See all the color sets

display.brewer.all( )

brewer.all

3) You can select one of the palettes above and view the palette in a graphics window.

display.brewer.pal(n=8, name=”Greens”) # a maximum of n depends on palette.

greens

4) If you are satisfied with these colors,  you can get their names which can be used in graphing in R.

colornames <- brewer.pal(n=8,name=”Greens”)
> colornames
[1] “#F7FCF5” “#E5F5E0” “#C7E9C0” “#A1D99B” “#74C476” “#41AB5D” “#238B45” “#005A32”

plot(x=1:8, y = rep(3, 8), col=colornames, pch=19, cex=8,  xaxt=’n’, yaxt=’n’, xlab=””, ylab=””, main =”Color Test”)

color test

I hope this post help you improve your figure with a better color choice!

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s