Fifty Shades of Grey in R

December 8, 2012

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

My wife went out to her book group tonight and their book of the month was 50 Shades of Grey. Sadly, I could think of is that plotting 50 shades in R would be a neat exercise.

grey50 <- data.frame(
	x = rep(1:10, 5),
	y = rep(1:5, each=10),
	c = unlist(lapply(seq(10,255,5), FUN=function(x) { rgb(x,x,x, max=255) })),
	t = unlist(lapply(seq(10,255,5), FUN=function(x) { ifelse(x > 255/2, 'black', 'white') }))
ggplot(grey50, aes(x=x, y=y, fill=c, label=c, color=t)) + 
	geom_tile() + geom_text(size=4) +
	scale_fill_identity() + scale_color_identity() + ylab(NULL) + xlab(NULL) + 
	theme(axis.ticks=element_blank(), axis.text=element_blank())

Fifty Shades of Grey in R

To leave a comment for the author, please follow the link and comment on their blog: Blog - R. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, 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...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)