On Tue, Jan 12, 2010 at 8:58 PM, Simon Knapp <sleepingwell@gmail.com> wrote:

>  Not sure if there are any 'recommended' visualisations, but the following
> is
> a start (you will need to tune the scaling of the x-axis label and state
> identifiers).
>
> In the plot produced, the widths of the 'columns' are proportional of
> purchases occurring in the state, and the height of the 'boxes' are
> proportional to the purchases occurring in the County - hence the area of
> each box represents the proportion of total (i.e. national) sales occurring
> in the County.
>
> #generate some random data
> n <- 100
> dat <- data.frame(
>    State=(tmp <- sample(LETTERS, n, T)),
>    County=paste(tmp, 1:n, sep=''),
>    Purchases=floor(rnorm(n, 100, 20))
> )
>
> # draw the plot
> split.dat <- split(dat, dat$State)
> widths <- sapply(split.dat, function(x) sum(x$Purchases))
> widths <- widths / sum(widths)
> cum.widths <- c(0.0, cumsum(widths)[-length(widths)])
> plot(0:1, 0:1, type='n', xaxt='n', yaxt='n', xlab='', ylab='')
> par(usr=c(0,1,0,1), xpd=NA)
> mapply(function(x, cum.tot, width) {
>    heights <- x$Purchases / sum(x$Purchases)
>    cum.heights <- c(0.0, cumsum(heights)[-length(heights)])
>    mapply(function(y, height, x, width) rect(x, y, x+width, y+height),
> cum.heights, heights, MoreArgs=list(cum.tot, width))
>    text(cum.tot + width/2, heights/2 + cum.heights, x$County)
> }, split.dat, cum.widths, widths)
>
> axis(1, (widths / 2 + cum.widths), names(split.dat))
>
>
>
> Hope this helps,
> Simon Knapp
>

This is great, Simon! I'm going to tweak this code some more.

Thanks,

Rex

	[[alternative HTML version deleted]]

