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

2006-07-26 Thread hadley wickham
 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

__
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.


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

2006-07-26 Thread Constantinos Antoniou
Hello,

I would like to make a question regarding the use of a grey background
(by ggplot in this case, but also in other settings - I seem to
remember a relevant lattice discussion). It seems that it is generally
discouraged by journals. I guess one practical reason is that it makes
photocopying difficult (in the sense that it may lead to low contrast
situations). It might have to do with printing costs, as it leads to
higher coverage of the page, but I do not know about that.

[Disclaimer: it does look nice, though.]

Any comments?

Thanks,

Costas

On 7/26/06, hadley wickham [EMAIL PROTECTED] 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

 __
 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.


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

2006-07-26 Thread Karl Ove Hufthammer
Constantinos Antoniou skreiv:

 I would like to make a question regarding the use of a grey background
 (by ggplot in this case, but also in other settings - I seem to
 remember a relevant lattice discussion). It seems that it is generally
 discouraged by journals. I guess one practical reason is that it makes
 photocopying difficult (in the sense that it may lead to low contrast
 situations). It might have to do with printing costs, as it leads to
 higher coverage of the page, but I do not know about that.
 
 [Disclaimer: it does look nice, though.]

 Any comments?

Just a small one: The grey background used by ggplot does look nice;
the one used by earlier versions of lattice did not. All IMHO, of course.

-- 
Karl Ove Hufthammer
E-mail and Jabber: [EMAIL PROTECTED]

__
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.


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

2006-07-26 Thread hadley wickham
 I would like to make a question regarding the use of a grey background
 (by ggplot in this case, but also in other settings - I seem to
 remember a relevant lattice discussion). It seems that it is generally
 discouraged by journals. I guess one practical reason is that it makes
 photocopying difficult (in the sense that it may lead to low contrast
 situations). It might have to do with printing costs, as it leads to
 higher coverage of the page, but I do not know about that.

 [Disclaimer: it does look nice, though.]

 Any comments?

It is very easy to change to the usual black on white grid lines (see
?ggopt and ?ggsave), so if your journal does require it, it's easy to
turn off.

Here are a few reasons I like the gray background (in no particular order):

 * you can then use white gridlines, which miniminally impinge on the
plot, but still aid lookup to the relevant axis

 * the color of the plot more closely matches the color (in the
typographic sense) of the text, so that the plot fits into a printed
document without drawing so much attention to itself.

 * the contrast between the plot surface and the points is a little
lower, which makes it a bit more pleasant to read

Of course the big disadvantage is if you don't have a high quality
printer, or a looking at a photocopy of a photocopy etc.  This
disadvantage should go away with time as the quality of printed output
steadily improves.

Regards,

Hadley

__
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.


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

2006-07-26 Thread John McHenry
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 [EMAIL PROTECTED] 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.


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

2006-07-26 Thread Gabor Grothendieck
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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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.


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

2006-07-25 Thread John McHenry
Gabor,

Your suggestion:

library(lattice)
xyplot(Consumption ~ Quarter, group = Year, data, type = o)

is very elegant indeed.

Thanks,

Jack.

Gabor Grothendieck [EMAIL PROTECTED] wrote: And if lattice is ok then try 
this:

library(lattice)
xyplot(Consumption ~ Quarter, group = Year, data, type = o)

On 7/24/06, Gabor Grothendieck  wrote:
 Try:

 matplot(levels(data$Quarter), matrix(data$Consumption, 4), type = o)


 On 7/24/06, John McHenry  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(YearQuarterConsumption
 19651874
 19652679
 19653616
 19654816
 
 19661866
 19662700
 19663603
 19664814
 
 19671843
 19672719
 19673594
 19674819
 
 19681906
 19682703
 19683634
 19684844
 
 19691952
 19692745
 19693635
 19694871), 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@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.
 




-

[[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] Overplotting: plot() invocation looks ugly ... suggestions?

2006-07-24 Thread John McHenry
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(YearQuarterConsumption
19651874
19652679
19653616
19654816

19661866
19662700
19663603
19664814

19671843
19672719
19673594
19674819

19681906
19682703
19683634
19684844

19691952
19692745
19693635
19694871), 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. Weacute;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.


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

2006-07-24 Thread Gabor Grothendieck
Try:

matplot(levels(data$Quarter), matrix(data$Consumption, 4), type = o)


On 7/24/06, John McHenry [EMAIL PROTECTED] 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(YearQuarterConsumption
19651874
19652679
19653616
19654816

19661866
19662700
19663603
19664814

19671843
19672719
19673594
19674819

19681906
19682703
19683634
19684844

19691952
19692745
19693635
19694871), 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@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.


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

2006-07-24 Thread Gabor Grothendieck
And if lattice is ok then try this:

library(lattice)
xyplot(Consumption ~ Quarter, group = Year, data, type = o)

On 7/24/06, Gabor Grothendieck [EMAIL PROTECTED] wrote:
 Try:

 matplot(levels(data$Quarter), matrix(data$Consumption, 4), type = o)


 On 7/24/06, John McHenry [EMAIL PROTECTED] 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(YearQuarterConsumption
 19651874
 19652679
 19653616
 19654816
 
 19661866
 19662700
 19663603
 19664814
 
 19671843
 19672719
 19673594
 19674819
 
 19681906
 19682703
 19683634
 19684844
 
 19691952
 19692745
 19693635
 19694871), 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@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.