[R] symbols(x,y, circles=sqrt(N)) with lattice xyplot
Deepayan Sarkar
deepayan.sarkar at gmail.com
Tue Sep 15 07:09:42 CEST 2009
On Mon, Sep 14, 2009 at 3:55 PM, Jacob Wegelin <jacob.wegelin at gmail.com> wrote:
> 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?
Yes, and the reason is that grid does not have a grid.symbols()
equivalent of symbols().
There are at least a couple of solutions (other than writing your own,
which is easy for circles). The first is to use the gridBase package
and use symbols(); there is an example at the end of the lattice book.
The other is to use grid.symbols() in Paul's grImport package, which
is much more general than symbols().
-Deepayan
> (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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list