[R] Drawing rectangles in multiple panels
Stephen Tucker
brown_emu at yahoo.com
Thu Jul 12 05:41:42 CEST 2007
Regarding this, I meant to imply that lattice was similarly flexible in the
sense of handing multiple data sets [IMHO], in regards to other aspects of
the 'grammar of graphics' I have no qualifications to justify comment. But
the idea and intuitiveness of graph construction in ggplot2 is very appealing
- in an hour I picked up enough to do quite a bit, just by going through
examples in the author's book <http://had.co.nz/ggplot2/>. Will be
interesting to see how this package will be received by the community.
Stephen
--- Stephen Tucker <brown_emu at yahoo.com> wrote:
> Not that Trellis/lattice was entirely easy to learn at first. :)
>
> I've been playing around with ggplot2 and there is a plot()-like wrapper
> for
> building a quick plot [incidentally, called qplot()], but otherwise it's my
> understanding that you superpose elements (incrementally) to build up to
> the
> graph you want. Here is the same plot in ggplot2:
>
> rectInfo <-
> list(matrix(runif(4), 2, 2),
> matrix(runif(4), 2, 2),
> matrix(runif(4), 2, 2))
>
> library(ggplot2)
> ggopt(grid.fill = "white") # just my preference
> ## original plot of points
> p <-
> qplot(x,y,data=data.frame(x=runif(30),y=runif(30),f=gl(3,30)),facets=f~.)
> # print(p)
>
> ## external data (rectangles) -> in coordinates for geom_polygon
> x <- do.call(rbind,
> mapply(function(.r,.f)
> data.frame(x=.r[c(1,1,2,2),1],y=.r[c(1,2,2,1),2],f=.f),
> .r=rectInfo,.f=seq(along=rectInfo),SIMPLIFY=FALSE))
> ## add rectangle to original plot of points
> p+layer(geom="polygon",data=x,mapping=aes(x=x,y=y),facets=f~.)
> # will print the graphics on my windows() device
>
> Though lattice does seem to emphasize the 'chart type' approach to
> graphing,
> in a way I see that it provides a similar flexibility - just that the
> specifications for each element are contained in functions and objects that
> are ultimately invoked by a high-level/higher-order function, instead of
> being combined in the linear fashion of ggplot2.
>
> ST
>
> --- Deepayan Sarkar <deepayan.sarkar at gmail.com> wrote:
>
> > On 7/11/07, hadley wickham <h.wickham at gmail.com> wrote:
> > > > A question/comment: I have usually found that the subscripts argument
> > is
> > > > what I need when passing *external* information into the panel
> > function, for
> > > > example, when I wish to add results from a fit done external to the
> > trellis
> > > > call. Fits[subscripts] gives me the fits (or whatever) I want to plot
> > for
> > > > each panel. It is not clear to me how the panel layout information
> from
> > > > panel.number(), etc. would be helpful here instead. Am I correct? --
> or
> > is
> > > > there a smarter way to do this that I've missed?
> > >
> > > This is one of things that I think ggplot does better - it's much
> > > easier to plot multiple data sources. I don't have many examples of
> > > this yet, but the final example on
> > > http://had.co.nz/ggplot2/geom_abline.html illustrates the basic idea.
> >
> > That's probably true. The Trellis approach is to define a plot by
> > "data source" + "type of plot", whereas the ggplot approach (if I
> > understand correctly) is to create a specification for the display
> > (incrementally?) and then render it. Since the specification can be
> > very general, the approach is very flexible. The downside is that you
> > need to learn the language.
> >
> > On a philosophical note, I think the apparent limitations of Trellis
> > in some (not all) cases is just due to the artificial importance given
> > to data frames as the one true container for data. Now that we have
> > proper multiple dispatch in S4, we can write methods that behave like
> > traditional Trellis calls but work with more complex data structures.
> > We have tried this in one bioconductor package (flowViz) with
> > encouraging results.
> >
> > -Deepayan
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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.
> >
>
>
>
>
>
____________________________________________________________________________________
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
____________________________________________________________________________________
Pinpoint customers who are looking for what you sell.
More information about the R-help
mailing list