Overplotting: plot() invocation looks ugly ... suggestions?
And if lattice is ok then try this: library(lattice) xyplot(Consumption ~ Quarter, group = Year, data, type = "o")
On 7/24/06, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
Try: matplot(levels(data$Quarter), matrix(data$Consumption, 4), type = "o") On 7/24/06, John McHenry <john_d_mchenry at yahoo.com> wrote:
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?re listening. Check out the handy changes to Yahoo! Groups.
[[alternative HTML version deleted]]
______________________________________________ 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.