Re: [R] Overplotting: plot() invocation looks ugly ... suggestions?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 27 Jul 2006 - 10:53:57 EST

With the lattice package it would be done like this (where the panel.points function places large red pluses on the plot):

xyplot(Consumption ~ Quarter, group = Year, data, type = "o") trellis.focus("panel", 1, 1)
panel.points(1:4, mean.per.quarter, pch = "+", cex = 2, col = "red") trellis.unfocus()

On 7/26/06, John McHenry <john_d_mchenry@yahoo.com> wrote:
> Hi Hadley,
>
> Thanks for your suggestion.
>
> The description of ggplot states:
>
> Description: ... It combines the advantages of both base and lattice
> graphics ... and you can still build up a plot step by
> step from multiple data sources
>
> So I thought I'd try to enhance the plot by adding in the means from each quarter (this is snagged directly from ESS):
>
> > qplot(Quarter, Consumption, data=data, type=c("point","line"), id=data$Year)
> ( mean.per.quarter<- with(data, tapply(Consumption, Quarter, mean)) )
> points(mean.per.quarter, pch="+", cex=2.0)
>
> qplot(Quarter, Consumption, data=data, type=c("point","line"), id=data$Year)
> > ( mean.per.quarter<- with(data, tapply(Consumption, Quarter, mean)) )
> 1 2 3 4
> 888.2 709.2 616.4 832.8
> > points(mean.per.quarter, pch="+", cex=2.0)
> Error in plot.xy(xy.coords(x, y), type = type, ...) :
> plot.new has not been called yet
> >
> >
>
> Now I'm green behind the ears when it comes to R, so I'm guessing that there is some major conflict between base graphics and lattice graphics, which I thought ggplot avoided, given the library help blurb.
>
> I'm assuming that there must be a way to add points / lines to lattice / ggplot graphics (in the latter case it seems to be via ggpoint, or some such)? But is there a way that allows me to add via:
>
> points(mean.per.quarter, pch="+", cex=2.0)
>
> and similar, or do I have to learn the lingo for lattice / ggplot?
>
> Thanks,
>
> Jack.
>
>
>
> hadley wickham <h.wickham@gmail.com> wrote: > And if lattice is ok then try this:
> >
> > library(lattice)
> > xyplot(Consumption ~ Quarter, group = Year, data, type = "o")
>
> Or you can use ggplot:
>
> install.packages("ggplot")
> library(ggplot)
> qplot(Quarter, Consumption, data=data,type=c("point","line"), id=data$Year)
>
> Unfortunately this has uncovered a couple of small bugs for me to fix
> (no automatic legend, and have to specify the data frame explicitly)
>
> The slighly more verbose example below shows you what it should look like.
>
> data$Year <- factor(data$Year)
> p <- ggplot(data, aes=list(x=Quarter, y=Consumption, id=Year, colour=Year))
> ggline(ggpoint(p), size=2)
>
> Regards,
>
> Hadley
>
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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@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. Received on Thu Jul 27 10:58:55 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 27 Jul 2006 - 12:17:57 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.