R365: Day 14 – theEconomist.theme

theEconomist.theme is probably one of the weirder things I have seen as part of a package, I ran into this while looking through stuff about spectral analysis. It helps to generate plots and diagrams that would look like they would fit in with the weekly journal The Economist (http://www.economist.com/). The set is part of the package {latticeExtras}. {lattice} and {latticeExtra} are awesome packages that I could probably talk about for a month each. Both help with graphing out things in R. The examples in both packages are phenomenal, and generate really interesting graphs that are fun to tweak and take apart.

asTheEconomist(xyplot(window(sunspot.year, start = 1700, end = 1900),lty=5,

main = “Sunspot cycles”, sub = “Number per year”))

This graph shows the number of visible sunspots from 1700 to 1900.

Rplot07

We can then use further tools within {latticeExtra} to highlight certain portions of the graph, like so:

asTheEconomist(xyplot(window(sunspot.year, start = 1700,end=1900),
                      main = "Sunspot cycles", sub = "Number per year"))

 trellis.last.object() +
     layer_(panel.xblocks(x, x >= 1880, col = "#6CCFF6", alpha = .5)) +
     layer(panel.text(1898, 140, "Forecast", font = 3, pos = 2))

Rplot

We can also look at deaths in Virginia; by tweaking it a bit so that it has stair-shaped lines, it looks a bit more like survival analysis! If only I could invert the values so that the curves go down…

asTheEconomist(
     dotplot(VADeaths, main = "Death Rates in Virginia (1940)",
            auto.key = list(corner = c(.9,0.1))),
     type = "s", with.bg = TRUE)

Rplot01

I struggled forever to change the text above the lines to the actual name groups of the singers, but I finally gave up…

asTheEconomist(
    densityplot(~ height, groups = voice.part, data = singer,
                  plot.points = FALSE, col= rainbow(8))) +
     glayer(d <- density(x), i <- which.max(d$y),
            ltext(d$x[i], d$y[i], paste("Group", group.number), pos = 3))
Rplot02
Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s