How to create an "inkblot" chart with R?

graphics, r

Solution

You can use `polygon` in base graphics, for instance

x <- seq(as.POSIXct("1949-01-01", tz="GMT"), length=36, by="months")
y <- rnorm(length(x))
plot(x, y, type="n", ylim=c(-1,1)*max(abs(y)))
polygon(c(x, rev(x)), c(y, -rev(y)), col="cornflowerblue", border=NA)

Update: Using `panel.polygon` from `lattice`:

library("lattice")
library("RColorBrewer")

df <- data.frame(x=rep(x,3),
                 y=rnorm(3*length(x)),
                 variable=gl(3, length(x)))

p <- xyplot(y~x|variable, data=df,
            ylim=c(-1,1)*max(abs(y)),
            layout=c(1,3),
            fill=brewer.pal(3, "Pastel2"),
            panel=function(...) {
              args <- list(...)
              print(args)
              panel.polygon(c(args$x, rev(args$x)),
                            c(args$y, -rev(args$y)),
                            fill=args$fill[panel.number()],
                            border=NA)
            })
print(p)

Problem

How can I create a chart like http://junkcharts.typepad.com/junk_charts/2010/01/leaving-ink-traces.html where several time series (one per country) are displayed horizontally as symmetric areas? I think if I could display one time series in this way, it is easy to generalize to several using mfrow. Sample data: ``` #Solar energy production in Europe, by country (EC),(1 000 toe) Country,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007 Belgium,1,1,1,1,1,1,2,2,3,3,3,5 Bulgaria,-,-,-,-,-,-,-,-,-,-,-,- Czech Republic,0,0,0,0,0,0,0,0,2,2,3,4 Denmark,6,7,7,8,8,8,9,9,9,10,10,11 Germany (including ex-GDR from 1991),57,70,83,78,96,150,184,216,262,353,472,580 Estonia,-,-,-,-,-,-,-,-,-,-,-,- Ireland,0,0,0,0,0,0,0,0,0,0,1,1 Greece,86,89,93,97,99,100,99,99,101,102,109,160 Spain,26,23,26,29,33,38,43,48,58,65,83,137 France,15,16,17,18,26,19,19,18,19,22,29,37 Italy,8,9,11,11,12,14,16,18,21,30,38,56 Cyprus,32,33,34,35,35,34,35,36,40,41,43,54 Latvia,-,-,-,-,-,-,-,-,-,-,-,- Lithuania,-,-,-,-,-,-,-,-,-,-,-,- Luxembourg (Grand-Duché),0,0,0,0,0,0,0,0,1,2,2,2 Hungary,0,0,0,0,0,1,2,2,2,2,2,3 Netherlands,6,7,8,10,12,14,16,19,20,22,22,23 Austria,42,48,55,58,64,69,74,80,86,92,101,108 Poland,0,0,0,0,0,0,0,0,0,0,0,0 Portugal,16,16,17,18,18,19,20,21,21,23,24,28 Romania,0,0,0,0,0,0,0,0,0,0,0,0 Slovenia,-,-,-,-,-,-,-,-,-,-,-,- Slovakia,0,0,0,0,0,0,0,0,0,0,0,0 Finland,0,0,0,0,1,1,1,1,1,1,1,1 Sweden,4,4,5,5,5,6,4,5,5,6,6,9 United Kingdom,6,6,7,7,11,13,16,20,25,30,37,46 Croatia,0,0,0,0,0,0,0,0,0,0,0,1 Turkey,159,179,210,236,262,287,318,350,375,385,402,420 Iceland,-,-,-,-,-,-,-,-,-,-,-,- Norway,0,0,0,0,0,0,0,0,0,0,0,0 Switzerland,18,19,21,23,24,26,23,24,25,26,28,30 #-='Not applicable' or 'Real zero' or 'Zero by default' :=Not available " #Source of Data:,Eurostat, http://spreadsheets.google.com/ccc?key=0Agol553XfuDZdFpCQU1CUVdPZ3M0djJBSE1za1NGV0E&hl=en_GB #Last Update:,30.04.2009 #Date of extraction:,17 Aug 2009 07:41:12 GMT, http://epp.eurostat.ec.europa.eu/tgm/table.do?tab=table&init=1&plugin=1&language=en&pcode=ten00082 ```

Original source