Skip to content

Instantly share code, notes, and snippets.

@jilmun
Last active April 2, 2016 14:36
Show Gist options
  • Save jilmun/1e93b013ceb1b2ae4da0780217424dcc to your computer and use it in GitHub Desktop.
Save jilmun/1e93b013ceb1b2ae4da0780217424dcc to your computer and use it in GitHub Desktop.
require(ggplot2)
# prepare simpsons data ---------------------------------------------------
# code from http://suehpro.blogspot.com/2016/03/the-simpsons-as-chart.html
d1 <- data.frame(member=c(rep("Homer",3),
rep("Marge",3),
rep("Bart",3),
rep("Lisa",2),
rep("Maggie",2)),
shade=c("HomerPants","HomerShirt","Skin",
"MargeDress","Skin","MargeHair",
"BartShorts","BartShirt","Skin",
"LisaDress","Skin",
"MaggieOnesie","Skin"),
height=c(20,20,25,
40,20,40,
15,15,18,
28,15,
18,11))
d1$member <- ordered(d1$member,levels=c("Homer","Marge","Bart","Lisa","Maggie"))
d1$shade <- ordered(d1$shade,levels=c("HomerPants","HomerShirt","Skin",
"MargeDress","MargeHair",
"BartShorts","BartShirt",
"LisaDress",
"MaggieOnesie"))
# chart the simpsons ------------------------------------------------------
# code from http://suehpro.blogspot.com/2016/03/the-simpsons-as-chart.html
g1 <- ggplot(d1,aes(x=member,y=height,fill=shade)) +
geom_bar(stat="identity") +
scale_fill_manual(values=c("#4F76DF","#FFFFFF","#FFD90F",
"#83C33F","#2359F1",
"#6686C7","#E65120",
"#DA6901",
"#72C7E7")) +
theme(legend.position="none",
axis.title.x=element_blank(),
axis.title.y=element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank()) +
ggtitle("Moe's Bar Chart")
g1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment