Fifty Shades of Grey in R

December 8, 2012
By

[This article was first published on Jason.Bryer.org Blog - R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

require(ggplot2)
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: Jason.Bryer.org Blog - R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.



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

Sponsors

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)