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

From: John McHenry <john_d_mchenry_at_yahoo.com>
Date: Tue 25 Jul 2006 - 11:28:35 EST


Hi WizaRds,

I'd like to overplot UK fuel consumption per quarter over the course of five years. Sounds simple enough?

Unless I'm missing something, the following seems very involved for what I'm trying to do. Any suggestions on simplifications?

The way I did it is awkward mainly because of the first call to plot ... but isn't this necessary, especially to set limits for the plot?

The second call to plot(), in conjunction with by(), seems to be natural enough, and, IMHO, seems to be readable and succinct.

    data<- read.table(textConnection("Year    Quarter        Consumption
    1965    1        874
    1965    2        679
    1965    3        616
    1965    4        816

    1966    1        866
    1966    2        700
    1966    3        603
    1966    4        814

    1967    1        843
    1967    2        719
    1967    3        594
    1967    4        819

    1968    1        906
    1968    2        703
    1968    3        634
    1968    4        844

    1969    1        952
    1969    2        745
    1969    3        635
    1969    4        871"), header=TRUE)
    data$Quarter<- as.factor(data$Quarter)
    #
    # what follows is only marginally less involved than using a for loop 
    # (the culprit is, in part, the need to make the first, type="n", call to plot()):
    windows(width=12,height=6)
    with(data, plot(levels(Quarter), Consumption[Year==Year[1]], ylim=c(min(Consumption), max(Consumption)), type="n"))     with(data, by(Consumption, Year, function(x) lines(levels(Quarter), x, type="o")))

Thanks,

Jack.                  



Groups are talking. We&acute;re listening. Check out the handy changes to Yahoo! Groups.

        [[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. Received on Tue Jul 25 12:46:19 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 Tue 25 Jul 2006 - 18:24:10 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.