[R] symbols(x,y, circles=sqrt(N)) with lattice xyplot

Jacob Wegelin jacob.wegelin at gmail.com
Tue Sep 15 00:55:02 CEST 2009


How would I create the following plot using lattice?

symbols( combPsummary$pastRate, combPsummary$finRate,
circles=sqrt(combPsummary$N) )

The idea is to plot finRate vs pastRate using circles whose areas are
proportional to the number of people in each group.

The following attempt does not really work:

   xyplot(
      finRate ~ pastRate
      , data=combPsummary
      , panel=function( x, y, ...) {
         panel.xyplot( x,y, type="n" )
         symbols( x , y, circles=sqrt(combPsummary$N))
         }
      )

It apparently first draws a rectangle, i.e., the lattice panel, and
then inside that rectangle it draws the same thing that is drawn by
the symbols() command outside of a panel function. That is, it draws
another rectangle in addition to the desired circles, and it writes
its own axis labels.

I didn't find "symbols" in the index of Deepayan's book. And I don't
think the xyplot help file deals with this either? I don't think there
is a "lsymbols" or "panel.symbols" function?

(Bill Cleveland points out that the human eye does not interpret area
accurately, so that making the area of a circle proportional to sample
size may be a flawed approach. Thus I'd also be interested in any
comments on how one might best graphically display x, y, and sample
size in a single plot.)

Thanks for any tips

Jake Wegelin




More information about the R-help mailing list