As described in a previous post, I had made a chart of Jack Kirby’s career as a comics artist. The finished product looked like this:
After thinking about it for a while I decided that I want to make some changes. First of all I want to indicate on the chart that Kirby no longer made his living from comics after 1980 (he moved into animation work). Second, maybe a straightforward connect-the-points line graph wasn’t such a great idea. The line spikes up and down a lot, making it difficult to see an overall trend. Instead, I think I want to plot the points and add a trend line using ggplot’s statistical smoothing function.
Step one: indicating Kirby’s retirement. I need to type the information for that into R.
jkhighlight <- data.frame(list(start=c(1943,1961,1980),end=c(1945,1970,1995), period=c("Military service","The Marvel Age","Retirement"))) jkhighlight$period <- factor(jkhighlight$period, levels=c("Military service","The Marvel Age","Retirement"))
(The last two lines above are to reorder the ‘period’ element so it’ll appear in chronological order in the key. Otherwise, the default is to alphabetical order: WWII, then retirement, then Marvel.)
Now to replot everything as points.
ggplot(yrtotals, aes(x=year,y=pages)) + geom_point()
This gives us:
last_plot() + theme_bw() last_plot() + scale_y_continuous("Published comic art pages per year") + scale_x_continuous("Source: marvelmasterworks.com", breaks=seq(from=1940,to=1995,by=5)) + opts(axis.title.x = theme_text(hjust=1, vjust=0, size=8), title="Jack Kirby's career in comics", plot.title=theme_text(hjust=0.5, vjust=1, size=16))
And add the colour regions:
last_plot() + geom_rect(aes(NULL, NULL, xmin=start, xmax=end, fill=as.factor(period)), ymin=0, ymax=1300, data=jkhighlight, alpha=0.3) + scale_fill_manual("", values=c("red", "orange","blue"))
Now we have:
last_plot() + coord_cartesian(ylim=c(0,1300),xlim=c(1937,1995)) last_plot() + stat_smooth(span=0.16)
I’m much happier with the way the graph looks now.