GGtutorial: Day 5 – Gradient Colors and Brewer Palettes

November 2, 2012

(This article was first published on is.R(), and kindly contributed to R-bloggers)

So, continuing with the short tutorials on how to do relatively simple (but sometimes very frustrating things) in ggplot, today’s post looks at how to use gradient colors and Brewer colors to color either continuous or discrete dependent variables. 

If you have a continuous dependent variable, you’ll want to use a gradient option that gently transitions between two specified colors. Some examples are below:

This is the output:

If you want to choose colors for factors or discrete variables, you might want to use a Brewer color scale (

This is the output:

To leave a comment for the author, please follow the link and comment on his blog: is.R(). offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , ,

Comments are closed.