South Park Characters in ggplot2
R Humor
A few days ago, I saw a post on r-bloggers that re-creates the Simpsons lego character images with ggplot2.
This was just so mind-blowingly awesome to me that I had to adapt The Clerk’s code for the South Park lego characters. Here’s my final code:
Because ggplot2 works with data frames, the first step is to create a data frame containing the character bars. Lines 4–19 create the d2 data frame that has a row for each rectangular section of the bar chart.
> d2
member shade height wideness
1 Eric EricPants 5 1.0
2 Eric EricShirt 20 1.0
3 Eric Skin 25 1.0
4 Eric EricHat 5 1.0
5 Eric EricPomPom 5 1.0
6 Kyle KylePants 5 0.5
7 Kyle KyleShirt 20 0.5
8 Kyle Skin 25 0.5
9 Kyle KyleHatBottom 5 0.5
10 Kyle KyleHatTop 5 0.5
11 Stan StanPants 5 0.5
12 Stan StanShirt 20 0.5
13 Stan Skin 25 0.5
14 Stan StanBottom 5 0.5
15 Stan StanHatTop 5 0.5
16 Kenny KennyOutfit 30 0.5
17 Kenny KennyBand 5 0.5
18 Kenny Skin 5 0.5
19 Kenny KennyBand 5 0.5
20 Kenny KennyOutfit 15 0.5
The main coding adjustment needed for this adaptation is to make Cartman’s bar wider. Having a variable width can be done in ggplot2 by adding a width argument to the ggplot call.
g2 <- ggplot(d2,aes(x=member,y=height,width=wideness,fill=shade))...
Other than that, just the names, heights and colors needed to be changed.
Two additional improvements that would be nice:
- Cartman’s pompom should have a smaller width than the rest of Cartman.
- The spacing between characters should be equal. As I have it now, Kyle is standing a little too close to Cartman.
But alas, I did not include these. Because <insert Cartman quote>.