Infoviz for multinomials: miniature plots within plots in R's ggplot

I'm plotting fluctuations in a trinomial distribution across two dimensions.

colorspace_plot - function(zz) {
    zz$z2 - zz$x * zz$y
 zz$z3 - zz$x * (1-zz$y)
    zz - cbind(zz, t(apply(zz[,c("z1","z2","z3")], 1, function(x) x/sum(x)) ))
    setnames(zz, c("x", "y", "z1", "z2", "z3", "p1", "p2", "p3"))
    zz$pcolor - with(zz, rgb(p1, p2, p3, 1))
 pcolors - zz$pcolor
    names(pcolors) - pcolors
    return( ggplot(zz, aes(x,y)) + geom_bin2d(aes(fill=pcolor), binwidth=1/11) +  scale_fill_manual(values = pcolors ) + guides(fill="none") )
}

clear - data.frame(x=rep(seq(from=0, to=1,length.out=11),times=11), y=rep(seq(from=0, to=1,length.out=11),each=11), z1=rep(1/3,11*11))
colorspace_plot(clear)

I don't know what its called, but this kind of plot has been used for this kind of thing before (Figure 4 here):

However, my actual data doesn't have the same clean separation of values as the ideal example. It's dominated by one of the three categories, so it comes out varying between clean and muddy variations of just one color. It doesn't communicate.

muddy - data.frame(x=rep(seq(from=0.6, to=1,length.out=11),times=11), y=rep(seq(from=0.6, to=1,length.out=11),each=11), z1=rep(1/3,11*11))
colorspace_plot(muddy)

While this plot still works, it doesn't "work".

My question: is there another way to represent trinomial data within-bin? For example: can I insert into each bin little pie charts or histograms, or something? A solution that stays within R and ggplot (and even with geom_bin2d()—I think I could figure this out with facet_grid()) would be ideal.

One promising idea that came up was to represent the distribution in each bin by filling each bin with a 10x10 grid of appropriately colored dots: a pointillist approach to my muddy plots. But I have no idea how to pull that off, or if it would even look good. Things I'll ask you to disregard:

  • rescaling the green or the mapping so that the other percentages come off larger than they really are.
  • breaking this one panel into three panels, one for each category.

Topic plotting ggplot2 infographics visualization r

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.