Skip to content

Instantly share code, notes, and snippets.

@nurandi
Last active August 29, 2015 14:15
Show Gist options
  • Save nurandi/17edc63574a1b80a3589 to your computer and use it in GitHub Desktop.
Save nurandi/17edc63574a1b80a3589 to your computer and use it in GitHub Desktop.
Creating grey colours palette in R
# Grey colours palette in R
# Credit to
# . Code: http://research.stowers-institute.org/efg/R/Color/Chart/
# . Graphics: http://www.mango-solutions.com/wp/2015/02/50-shades-of-grey-according-to-r
greys = grep("^grey", colours(), value = TRUE)
colCount <- 6
rowCount <- 17
plot( c(1,colCount), c(0,rowCount), type="n", ylab="", xlab="",
axes=FALSE, ylim=c(rowCount,0))
title("R\'s 102 Shades of Grey")
for (j in 0:(rowCount-1))
{
base <- j*colCount
remaining <- length(greys) - base
RowSize <- ifelse(remaining < colCount, remaining, colCount)
rect((1:RowSize)-0.5,j-0.5, (1:RowSize)+0.5,j+0.5,
border="black",
col=greys[base + (1:RowSize)])
text((1:RowSize), j, greys[j*RowSize + 1:RowSize], cex=0.7,
col=(ifelse(j<=8, "white", "black")))
}
# R's 50 Shades of Grey
# Credit to: http://www.mango-solutions.com/wp/2015/02/50-shades-of-grey-according-to-r
shadesOfGrey <- colorRampPalette(c("grey0", "grey100"))
fiftyGreys <- shadesOfGrey(50)
mat <- matrix(rep(1:50, each = 50))
image(mat, axes = FALSE, col = fiftyGreys)
title("R\'s 50 Shades of Grey")
box()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment