Get a long color palette with RColorBrewer



This post describes how to get a long color palette with R and the RColorBrewer package.

Base R color Section About line chart

The RColorBrewer package is a great tool when it comes to build a color palette with R. However, the default palettes give only about 10 different colors. Here is a tip to get more colors in a graph, still using this useful package. Basically, it relies on the colorRampPalette() function to extand a first palette.

Note: visit this post for a complete list of the available palettes.



# No margin
par(mar=c(0,0,1,0))

# Load RColorBrewer
library(RColorBrewer)

# Classic palette BuPu, with 4 colors
coul <- brewer.pal(4, "PuOr") 

# Add more colors to this palette :
coul <- colorRampPalette(coul)(25)

# Plot it
pie(rep(1, length(coul)), col = coul , main="") 

Related chart types


Ggplot2
Animation
Interactivity
3D
Caveats
Data art



❤️ 10 best R tricks ❤️

👋 After crafting hundreds of R charts over 12 years, I've distilled my top 10 tips and tricks. Receive them via email! One insight per day for the next 10 days! 🔥