Re: [R] lattice: how to center a subtitle?

2011-04-05 Thread Deepayan Sarkar
On Tue, Apr 5, 2011 at 6:12 AM, David Scott d.sc...@auckland.ac.nz wrote:

[...]

 I am not sure where I read it and I can't find it again, but my
 understanding is that expressions using bquote with lattice need to be
 enclosed in as.expression() to work. That is in contrast to what happens in
 base graphics.

 Here is a simple example.

 a - 2
 plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
 require(lattice)
 xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
 xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a

 Which produces:

 a - 2
 plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
 require(lattice)
 Loading required package: lattice
 xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
 Error in trellis.skeleton(formula = a * (1:10) ~ 1:10, cond = list(c(1L,  :
  object 'alpha' not found
 xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a

 Using expression() rather than as.expression() doesn't produce the desired
 affect. Try it yourself.

 As to why this is the case .

Let's see: ?xyplot says

  'main': Typically a character string or expression describing
  the main title to be placed on top of each page. [...]

So, lattice is fairly explicit, by R standards, in requiring 'main' to
be character or expression. On the other hand, ?title says

 The labels passed to 'title' can be character strings or language
 objects (names, calls or expressions), or [...]

so it additionally accepts names and calls.

Now, we have

 a - 2
 foo - bquote(alpha == .(a))

 foo # Looks OK
alpha == 2
 mode(foo) # But
[1] call
 is.expression(foo) # not an expression
[1] FALSE

 is.expression(expression(foo)) ## YES, but
[1] TRUE
 expression(foo) ## not what we want
expression(foo)

 is.expression(as.expression(foo))
[1] TRUE
 as.expression(foo) ## This IS what we want
expression(alpha == 2)

So I submit that lattice is behaving exactly as suggested by its documentation.

Now you would naturally argue that this is hiding behind
technicalities, and if call objects work for plot(), it should work
for lattice as well. But watch this:

 plot(1:10, main = foo) # works perfectly

 arglist - list(1:10, main = foo)
 arglist # Looks like what we want
[[1]]
 [1]  1  2  3  4  5  6  7  8  9 10

$main
alpha == 2

 do.call(plot, arglist)
Error in as.graphicsAnnot(main) : object 'alpha' not found

...which I would say is unexpected behaviour, if not a bug.

The moral of the story is that unevaluated calls are dangerous objects
(try this one out for fun:

foo - bquote(q(.(x)), list(x = no))
do.call(plot, list(1:10, main = foo))

), and carrying them around is not a good idea.

Lattice does use the do.call paradigm quite a bit, and I think it
might be quite difficult to fix it up to handle non-expression
language objects (which will still not fix the type of problem shown
above).

-Deepayan

__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-05 Thread David Scott

On 6/04/2011 12:47 a.m., Deepayan Sarkar wrote:

On Tue, Apr 5, 2011 at 6:12 AM, David Scottd.sc...@auckland.ac.nz  wrote:

[...]


I am not sure where I read it and I can't find it again, but my
understanding is that expressions using bquote with lattice need to be
enclosed in as.expression() to work. That is in contrast to what happens in
base graphics.

Here is a simple example.

a- 2
plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
require(lattice)
xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a

Which produces:


a- 2
plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
require(lattice)

Loading required package: lattice

xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))

Error in trellis.skeleton(formula = a * (1:10) ~ 1:10, cond = list(c(1L,  :
  object 'alpha' not found

xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a


Using expression() rather than as.expression() doesn't produce the desired
affect. Try it yourself.

As to why this is the case .


Let's see: ?xyplot says

   'main': Typically a character string or expression describing
   the main title to be placed on top of each page. [...]

So, lattice is fairly explicit, by R standards, in requiring 'main' to
be character or expression. On the other hand, ?title says

  The labels passed to 'title' can be character strings or language
  objects (names, calls or expressions), or [...]

so it additionally accepts names and calls.

Now, we have


a- 2
foo- bquote(alpha == .(a))



foo # Looks OK

alpha == 2

mode(foo) # But

[1] call

is.expression(foo) # not an expression

[1] FALSE


is.expression(expression(foo)) ## YES, but

[1] TRUE

expression(foo) ## not what we want

expression(foo)


is.expression(as.expression(foo))

[1] TRUE

as.expression(foo) ## This IS what we want

expression(alpha == 2)

So I submit that lattice is behaving exactly as suggested by its documentation.

Now you would naturally argue that this is hiding behind
technicalities, and if call objects work for plot(), it should work
for lattice as well. But watch this:


plot(1:10, main = foo) # works perfectly



arglist- list(1:10, main = foo)
arglist # Looks like what we want

[[1]]
  [1]  1  2  3  4  5  6  7  8  9 10

$main
alpha == 2


do.call(plot, arglist)

Error in as.graphicsAnnot(main) : object 'alpha' not found

...which I would say is unexpected behaviour, if not a bug.

The moral of the story is that unevaluated calls are dangerous objects
(try this one out for fun:

foo- bquote(q(.(x)), list(x = no))
do.call(plot, list(1:10, main = foo))

), and carrying them around is not a good idea.

Lattice does use the do.call paradigm quite a bit, and I think it
might be quite difficult to fix it up to handle non-expression
language objects (which will still not fix the type of problem shown
above).

-Deepayan


Thanks very much for this explanation Deepayan. Part of my intention in 
contributing to this thread was to have something explicit in the 
archives for future reference, and your reply is excellent in that regard.


And many thanks for your work on lattice.

David Scott

--
_
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread Marius Hofert
Dear expeRts,

I recently asked for a real centered title (see, e.g., 
http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html). 
A nice solution (from Deepayan Sarkar) is to use xlab.top instead of main:

library(lattice)
trellis.device(pdf) 
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's 
eye, sub = but subtitles are not centered, scales = list(alternating = 
c(1,1), tck = c(1,0 
dev.off()

My question is whether there is something similar for *sub*titles [so something 
like xlab.bottom]? As you can see from the plot, the subtitle does not seem 
to be centered for the human's eye. I would like to center it according to 
the x-axis label. 

Cheers,

Marius
__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread David Winsemius


On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:


Dear expeRts,

I recently asked for a real centered title (see, e.g., http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html) 
.
A nice solution (from Deepayan Sarkar) is to use xlab.top instead  
of main:


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the  
human's eye, sub = but subtitles are not centered, scales =  
list(alternating = c(1,1), tck = c(1,0

dev.off()


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the  
human's eye, xlab = but subtitles are _now_ centered, scales =  
list(alternating = c(1,1), tck = c(1,0

dev.off()


(I realize that those are not really subtitles by a 'lab', but that  
appears acceptable in your current test case.)




My question is whether there is something similar for *sub*titles  
[so something like xlab.bottom]? As you can see from the plot, the  
subtitle does not seem to be centered for the human's eye. I would  
like to center it according to the x-axis label.





David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread Marius Hofert
Dear David,

I intended to use another x-label. But your suggestion brings me to the idea of 
just using a two-line xlab, so s.th. like
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's 
eye, xlab = but subtitles are _now_ centered\nbla, scales = list(alternating 
= c(1,1), tck = c(1,0

Thanks!

Cheers,

Marius

On 2011-04-04, at 16:47 , David Winsemius wrote:

 
 On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:
 
 Dear expeRts,
 
 I recently asked for a real centered title (see, e.g., 
 http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html).
 A nice solution (from Deepayan Sarkar) is to use xlab.top instead of 
 main:
 
 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's 
 eye, sub = but subtitles are not centered, scales = list(alternating = 
 c(1,1), tck = c(1,0
 dev.off()
 
 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's 
 eye, xlab = but subtitles are _now_ centered, scales = list(alternating = 
 c(1,1), tck = c(1,0
 dev.off()
 
 
 (I realize that those are not really subtitles by a 'lab', but that appears 
 acceptable in your current test case.)
 
 
 My question is whether there is something similar for *sub*titles [so 
 something like xlab.bottom]? As you can see from the plot, the subtitle 
 does not seem to be centered for the human's eye. I would like to center 
 it according to the x-axis label.
 
 
 
 David Winsemius, MD
 West Hartford, CT
 

__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread David Winsemius


On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:


Dear David,

I intended to use another x-label. But your suggestion brings me to  
the idea of just using a two-line xlab, so s.th. like
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the  
human's eye, xlab = but subtitles are _now_ centered\nbla, scales  
= list(alternating = c(1,1), tck = c(1,0


And if you wanted different fontface (underline, italic or bold) then  
you could use plotmath expressions:


xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's  
eye, xlab =  
expression( atop(but~subtitles2~are~underline(now)~centered,  
bold(bla) )), scales = list(alternating = c(1,1), tck = c(1,0)))


--
David.



Thanks!

Cheers,

Marius

On 2011-04-04, at 16:47 , David Winsemius wrote:



On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:


Dear expeRts,

I recently asked for a real centered title (see, e.g., http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html) 
.
A nice solution (from Deepayan Sarkar) is to use xlab.top  
instead of main:


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for  
the human's eye, sub = but subtitles are not centered, scales =  
list(alternating = c(1,1), tck = c(1,0

dev.off()


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for  
the human's eye, xlab = but subtitles are _now_ centered, scales  
= list(alternating = c(1,1), tck = c(1,0

dev.off()


(I realize that those are not really subtitles by a 'lab', but that  
appears acceptable in your current test case.)




My question is whether there is something similar for *sub*titles  
[so something like xlab.bottom]? As you can see from the plot,  
the subtitle does not seem to be centered for the human's eye. I  
would like to center it according to the x-axis label.





David Winsemius, MD
West Hartford, CT





David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread Marius Hofert
Dear David,

do you know how to get plotmath-like symbols in both rows?
I tried s.th. like:

lab - expression(paste(alpha==1, , , beta==2, sep=))
xlab - substitute(expression( atop(lab==lab., bold(foo)) ), list(lab.=lab))
xyplot(0 ~ 0, xlab = xlab)

Cheers,

Marius

On 2011-04-04, at 18:59 , David Winsemius wrote:

 
 On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:
 
 Dear David,
 
 I intended to use another x-label. But your suggestion brings me to the idea 
 of just using a two-line xlab, so s.th. like
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's 
 eye, xlab = but subtitles are _now_ centered\nbla, scales = 
 list(alternating = c(1,1), tck = c(1,0
 
 And if you wanted different fontface (underline, italic or bold) then you 
 could use plotmath expressions:
 
 xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's eye, 
 xlab = expression( atop(but~subtitles2~are~underline(now)~centered, bold(bla) 
 )), scales = list(alternating = c(1,1), tck = c(1,0)))
 
 -- 
 David.
 
 
 Thanks!
 
 Cheers,
 
 Marius
 
 On 2011-04-04, at 16:47 , David Winsemius wrote:
 
 
 On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:
 
 Dear expeRts,
 
 I recently asked for a real centered title (see, e.g., 
 http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html).
 A nice solution (from Deepayan Sarkar) is to use xlab.top instead of 
 main:
 
 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the 
 human's eye, sub = but subtitles are not centered, scales = 
 list(alternating = c(1,1), tck = c(1,0
 dev.off()
 
 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the 
 human's eye, xlab = but subtitles are _now_ centered, scales = 
 list(alternating = c(1,1), tck = c(1,0
 dev.off()
 
 
 (I realize that those are not really subtitles by a 'lab', but that appears 
 acceptable in your current test case.)
 
 
 My question is whether there is something similar for *sub*titles [so 
 something like xlab.bottom]? As you can see from the plot, the subtitle 
 does not seem to be centered for the human's eye. I would like to center 
 it according to the x-axis label.
 
 
 
 David Winsemius, MD
 West Hartford, CT
 
 
 
 David Winsemius, MD
 West Hartford, CT
 

__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread David Winsemius


On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote:


Dear David,

do you know how to get plotmath-like symbols in both rows?
I tried s.th. like:

lab - expression(paste(alpha==1, , , beta==2, sep=))
xlab - substitute(expression( atop(lab==lab., bold(foo)) ),  
list(lab.=lab))

xyplot(0 ~ 0, xlab = xlab)


I _did_ have plotmath functions in both rows: But here is your solution:

xyplot(0 ~ 0,  xlab =
expression( atop(paste(alpha==1,, beta==2), bold(bla) )) )
  )

Note that `paste` in plotmath is different than `paste` in regular R.  
It has no `sep` argument. I did try both substitute and bquote on you  
externally expression,  but lattice seems to be doing some non- 
standard evaluation and I never got it to work. Using what I thought  
_should_ work, does work with `plot`:


 x=1;y=2
 plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y),  
bold(foo) ) )

+ )

But the same expression throws an error with xyplot:
 x=1;y=2
 xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y),  
bold(foo) ) )

+ )
Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect =  
fill,  :

  could not find function atop

--
David.




Cheers,

Marius

On 2011-04-04, at 18:59 , David Winsemius wrote:



On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:


Dear David,

I intended to use another x-label. But your suggestion brings me  
to the idea of just using a two-line xlab, so s.th. like
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for  
the human's eye, xlab = but subtitles are _now_ centered\nbla,  
scales = list(alternating = c(1,1), tck = c(1,0


And if you wanted different fontface (underline, italic or bold)  
then you could use plotmath expressions:


xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the  
human's eye, xlab =  
expression( atop(but~subtitles2~are~underline(now)~centered,  
bold(bla) )), scales = list(alternating = c(1,1), tck = c(1,0)))


--
David.



Thanks!

Cheers,

Marius

On 2011-04-04, at 16:47 , David Winsemius wrote:



On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:


Dear expeRts,

I recently asked for a real centered title (see, e.g., http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html) 
.
A nice solution (from Deepayan Sarkar) is to use xlab.top  
instead of main:


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for  
the human's eye, sub = but subtitles are not centered, scales  
= list(alternating = c(1,1), tck = c(1,0

dev.off()


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for  
the human's eye, xlab = but subtitles are _now_ centered,  
scales = list(alternating = c(1,1), tck = c(1,0

dev.off()


(I realize that those are not really subtitles by a 'lab', but  
that appears acceptable in your current test case.)




My question is whether there is something similar for  
*sub*titles [so something like xlab.bottom]? As you can see  
from the plot, the subtitle does not seem to be centered for  
the human's eye. I would like to center it according to the x- 
axis label.





David Winsemius, MD
West Hartford, CT





David Winsemius, MD
West Hartford, CT





David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread Peter Ehlers

On 2011-04-04 10:27, Marius Hofert wrote:

Dear David,

do you know how to get plotmath-like symbols in both rows?
I tried s.th. like:

lab- expression(paste(alpha==1, , , beta==2, sep=))
xlab- substitute(expression( atop(lab==lab., bold(foo)) ), list(lab.=lab))
xyplot(0 ~ 0, xlab = xlab)


Marius,

I always find paste a bit tricky with plotmath.
Maybe this will do what you want:

 mylab - expression( atop(lab==list(alpha==1, beta==2), bold(foo)) )
 xyplot(0 ~ 0, xlab = mylab)

Peter Ehlers



Cheers,

Marius

On 2011-04-04, at 18:59 , David Winsemius wrote:



On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:


Dear David,

I intended to use another x-label. But your suggestion brings me to the idea of 
just using a two-line xlab, so s.th. like
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's eye, xlab = 
but subtitles are _now_ centered\nbla, scales = list(alternating = c(1,1), tck = 
c(1,0


And if you wanted different fontface (underline, italic or bold) then you could 
use plotmath expressions:

xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's eye, 
xlab = expression( atop(but~subtitles2~are~underline(now)~centered, bold(bla) )), scales 
= list(alternating = c(1,1), tck = c(1,0)))

--
David.



Thanks!

Cheers,

Marius

On 2011-04-04, at 16:47 , David Winsemius wrote:



On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:


Dear expeRts,

I recently asked for a real centered title (see, e.g., 
http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html).
A nice solution (from Deepayan Sarkar) is to use xlab.top instead of main:

library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's eye, sub = 
but subtitles are not centered, scales = list(alternating = c(1,1), tck = c(1,0
dev.off()


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's eye, xlab = 
but subtitles are _now_ centered, scales = list(alternating = c(1,1), tck = c(1,0
dev.off()


(I realize that those are not really subtitles by a 'lab', but that appears 
acceptable in your current test case.)



My question is whether there is something similar for *sub*titles [so something like 
xlab.bottom]? As you can see from the plot, the subtitle does not seem to be 
centered for the human's eye. I would like to center it according to the x-axis label.




David Winsemius, MD
West Hartford, CT





David Winsemius, MD
West Hartford, CT



__
R-help@r-project.org 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@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread Henrique Dallazuanna
Maybe:

xyplot(0 ~ 0, xlab =
bquote(expression(atop(alpha==.(x)*,~beta==.(y), bold(foo) )) ))

On Mon, Apr 4, 2011 at 2:58 PM, David Winsemius dwinsem...@comcast.net wrote:

 On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote:

 Dear David,

 do you know how to get plotmath-like symbols in both rows?
 I tried s.th. like:

 lab - expression(paste(alpha==1, , , beta==2, sep=))
 xlab - substitute(expression( atop(lab==lab., bold(foo)) ),
 list(lab.=lab))
 xyplot(0 ~ 0, xlab = xlab)

 I _did_ have plotmath functions in both rows: But here is your solution:

 xyplot(0 ~ 0,  xlab =
    expression( atop(paste(alpha==1,    , beta==2), bold(bla) )) )
      )

 Note that `paste` in plotmath is different than `paste` in regular R. It has
 no `sep` argument. I did try both substitute and bquote on you externally
 expression,  but lattice seems to be doing some non-standard evaluation and
 I never got it to work. Using what I thought _should_ work, does work with
 `plot`:

 x=1;y=2
 plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y), bold(foo) ) )
 + )

 But the same expression throws an error with xyplot:
 x=1;y=2
 xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y), bold(foo) )
 )
 + )
 Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect = fill,
  :
  could not find function atop

 --
 David.



 Cheers,

 Marius

 On 2011-04-04, at 18:59 , David Winsemius wrote:


 On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:

 Dear David,

 I intended to use another x-label. But your suggestion brings me to the
 idea of just using a two-line xlab, so s.th. like
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the
 human's eye, xlab = but subtitles are _now_ centered\nbla, scales =
 list(alternating = c(1,1), tck = c(1,0

 And if you wanted different fontface (underline, italic or bold) then you
 could use plotmath expressions:

 xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's
 eye, xlab = expression( atop(but~subtitles2~are~underline(now)~centered,
 bold(bla) )), scales = list(alternating = c(1,1), tck = c(1,0)))

 --
 David.


 Thanks!

 Cheers,

 Marius

 On 2011-04-04, at 16:47 , David Winsemius wrote:


 On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:

 Dear expeRts,

 I recently asked for a real centered title (see, e.g.,
 http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html).
 A nice solution (from Deepayan Sarkar) is to use xlab.top instead of
 main:

 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the
 human's eye, sub = but subtitles are not centered, scales =
 list(alternating = c(1,1), tck = c(1,0
 dev.off()

 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the
 human's eye, xlab = but subtitles are _now_ centered, scales =
 list(alternating = c(1,1), tck = c(1,0
 dev.off()


 (I realize that those are not really subtitles by a 'lab', but that
 appears acceptable in your current test case.)


 My question is whether there is something similar for *sub*titles [so
 something like xlab.bottom]? As you can see from the plot, the subtitle
 does not seem to be centered for the human's eye. I would like to 
 center
 it according to the x-axis label.



 David Winsemius, MD
 West Hartford, CT



 David Winsemius, MD
 West Hartford, CT



 David Winsemius, MD
 West Hartford, CT

 __
 R-help@r-project.org 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.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread Marius Hofert
Dear all,

many thanks, that helped a lot!

Cheers,

Marius

On 2011-04-04, at 19:58 , David Winsemius wrote:

 
 On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote:
 
 Dear David,
 
 do you know how to get plotmath-like symbols in both rows?
 I tried s.th. like:
 
 lab - expression(paste(alpha==1, , , beta==2, sep=))
 xlab - substitute(expression( atop(lab==lab., bold(foo)) ), list(lab.=lab))
 xyplot(0 ~ 0, xlab = xlab)
 
 I _did_ have plotmath functions in both rows: But here is your solution:
 
 xyplot(0 ~ 0,  xlab =
expression( atop(paste(alpha==1,, beta==2), bold(bla) )) )
  )
 
 Note that `paste` in plotmath is different than `paste` in regular R. It has 
 no `sep` argument. I did try both substitute and bquote on you externally 
 expression,  but lattice seems to be doing some non-standard evaluation and I 
 never got it to work. Using what I thought _should_ work, does work with 
 `plot`:
 
  x=1;y=2
  plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y), bold(foo) ) )
 + )
 
 But the same expression throws an error with xyplot:
  x=1;y=2
  xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y), bold(foo) ) )
 + )
 Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect = fill,  
 :
  could not find function atop
 
 -- 
 David.
 
 
 
 Cheers,
 
 Marius
 
 On 2011-04-04, at 18:59 , David Winsemius wrote:
 
 
 On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:
 
 Dear David,
 
 I intended to use another x-label. But your suggestion brings me to the 
 idea of just using a two-line xlab, so s.th. like
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the 
 human's eye, xlab = but subtitles are _now_ centered\nbla, scales = 
 list(alternating = c(1,1), tck = c(1,0
 
 And if you wanted different fontface (underline, italic or bold) then you 
 could use plotmath expressions:
 
 xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's 
 eye, xlab = expression( atop(but~subtitles2~are~underline(now)~centered, 
 bold(bla) )), scales = list(alternating = c(1,1), tck = c(1,0)))
 
 -- 
 David.
 
 
 Thanks!
 
 Cheers,
 
 Marius
 
 On 2011-04-04, at 16:47 , David Winsemius wrote:
 
 
 On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:
 
 Dear expeRts,
 
 I recently asked for a real centered title (see, e.g., 
 http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html).
 A nice solution (from Deepayan Sarkar) is to use xlab.top instead of 
 main:
 
 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the 
 human's eye, sub = but subtitles are not centered, scales = 
 list(alternating = c(1,1), tck = c(1,0
 dev.off()
 
 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the 
 human's eye, xlab = but subtitles are _now_ centered, scales = 
 list(alternating = c(1,1), tck = c(1,0
 dev.off()
 
 
 (I realize that those are not really subtitles by a 'lab', but that 
 appears acceptable in your current test case.)
 
 
 My question is whether there is something similar for *sub*titles [so 
 something like xlab.bottom]? As you can see from the plot, the 
 subtitle does not seem to be centered for the human's eye. I would 
 like to center it according to the x-axis label.
 
 
 
 David Winsemius, MD
 West Hartford, CT
 
 
 
 David Winsemius, MD
 West Hartford, CT
 
 
 
 David Winsemius, MD
 West Hartford, CT
 

__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread David Scott

 On 05/04/11 05:58, David Winsemius wrote:

On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote:


Dear David,

do you know how to get plotmath-like symbols in both rows?
I tried s.th. like:

lab- expression(paste(alpha==1, , , beta==2, sep=))
xlab- substitute(expression( atop(lab==lab., bold(foo)) ),
list(lab.=lab))
xyplot(0 ~ 0, xlab = xlab)

I _did_ have plotmath functions in both rows: But here is your solution:

xyplot(0 ~ 0,  xlab =
  expression( atop(paste(alpha==1,, beta==2), bold(bla) )) )
)

Note that `paste` in plotmath is different than `paste` in regular R.
It has no `sep` argument. I did try both substitute and bquote on you
externally expression,  but lattice seems to be doing some non-
standard evaluation and I never got it to work. Using what I thought
_should_ work, does work with `plot`:

x=1;y=2
plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y),
bold(foo) ) )
+ )

But the same expression throws an error with xyplot:
x=1;y=2
xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y),
bold(foo) ) )
+ )
Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect =
fill,  :
could not find function atop

I am not sure where I read it and I can't find it again, but my 
understanding is that expressions using bquote with lattice need to be 
enclosed in as.expression() to work. That is in contrast to what happens 
in base graphics.


Here is a simple example.

a - 2
plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
require(lattice)
xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a

Which produces:

 a - 2
 plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
 require(lattice)
Loading required package: lattice
 xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
Error in trellis.skeleton(formula = a * (1:10) ~ 1:10, cond = list(c(1L,  :
  object 'alpha' not found
 xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a

Using expression() rather than as.expression() doesn't produce the 
desired affect. Try it yourself.


As to why this is the case .

David Scott

--
_
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread David Winsemius


On Apr 4, 2011, at 8:42 PM, David Scott wrote:


On 05/04/11 05:58, David Winsemius wrote:

On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote:


Dear David,

do you know how to get plotmath-like symbols in both rows?
I tried s.th. like:

lab- expression(paste(alpha==1, , , beta==2, sep=))
xlab- substitute(expression( atop(lab==lab., bold(foo)) ),
list(lab.=lab))
xyplot(0 ~ 0, xlab = xlab)
I _did_ have plotmath functions in both rows: But here is your  
solution:


xyplot(0 ~ 0,  xlab =
 expression( atop(paste(alpha==1,, beta==2), bold(bla) )) )
   )

Note that `paste` in plotmath is different than `paste` in regular R.
It has no `sep` argument. I did try both substitute and bquote on you
externally expression,  but lattice seems to be doing some non-
standard evaluation and I never got it to work. Using what I  
thought

_should_ work, does work with `plot`:

   x=1;y=2
   plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y),
bold(foo) ) )
+ )

But the same expression throws an error with xyplot:
   x=1;y=2
   xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y),
bold(foo) ) )
+ )
Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect =
fill,  :
   could not find function atop




I am not sure where I read it and I can't find it again, but my  
understanding is that expressions using bquote with lattice need to  
be enclosed in as.expression() to work. That is in contrast to what  
happens in base graphics.


Here is a simple example.

a - 2
plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
require(lattice)
xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a

Which produces:

 a - 2
 plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
 require(lattice)
Loading required package: lattice
 xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
Error in trellis.skeleton(formula = a * (1:10) ~ 1:10, cond =  
list(c(1L,  :

 object 'alpha' not found
 xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a

Using expression() rather than as.expression() doesn't produce the  
desired affect. Try it yourself.


I did. Your theory seems supported by the experimental evidence:

lab - bquote(paste(alpha==1, , , beta==2))
xyplot(0 ~ 0, xlab = as.expression(bquote(atop(.(lab), bold(foo) ) )))

# Works!



As to why this is the case .


Right. It does seem as though we should need to be deducing the inner  
workings of the subatomic particles by throwing text at the  
interpreter though.


--

David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread David Winsemius


On Apr 4, 2011, at 9:03 PM, David Winsemius wrote:



On Apr 4, 2011, at 8:42 PM, David Scott wrote:


On 05/04/11 05:58, David Winsemius wrote:

On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote:


Dear David,

do you know how to get plotmath-like symbols in both rows?
I tried s.th. like:

lab- expression(paste(alpha==1, , , beta==2, sep=))
xlab- substitute(expression( atop(lab==lab., bold(foo)) ),
list(lab.=lab))
xyplot(0 ~ 0, xlab = xlab)
I _did_ have plotmath functions in both rows: But here is your  
solution:


xyplot(0 ~ 0,  xlab =
expression( atop(paste(alpha==1,, beta==2), bold(bla) )) )
  )

Note that `paste` in plotmath is different than `paste` in regular  
R.
It has no `sep` argument. I did try both substitute and bquote on  
you

externally expression,  but lattice seems to be doing some non-
standard evaluation and I never got it to work. Using what I  
thought

_should_ work, does work with `plot`:

  x=1;y=2
  plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y),
bold(foo) ) )
+ )

But the same expression throws an error with xyplot:
  x=1;y=2
  xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y),
bold(foo) ) )
+ )
Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect =
fill,  :
  could not find function atop




I am not sure where I read it and I can't find it again, but my  
understanding is that expressions using bquote with lattice need to  
be enclosed in as.expression() to work. That is in contrast to what  
happens in base graphics.


Perhaps here:
http://finzi.psych.upenn.edu/Rhelp10/2010-August/250832.html

Or here:
http://finzi.psych.upenn.edu/Rhelp10/2009-July/203714.html

Although I disagree with Heimstra that reading the help(bquote)  
provides more details that might shed light on why this is so.


--
David.




Here is a simple example.

a - 2
plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
require(lattice)
xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a

Which produces:

 a - 2
 plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
 require(lattice)
Loading required package: lattice
 xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
Error in trellis.skeleton(formula = a * (1:10) ~ 1:10, cond =  
list(c(1L,  :

object 'alpha' not found
 xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a

Using expression() rather than as.expression() doesn't produce the  
desired affect. Try it yourself.


I did. Your theory seems supported by the experimental evidence:

lab - bquote(paste(alpha==1, , , beta==2))
xyplot(0 ~ 0, xlab = as.expression(bquote(atop(.(lab), bold(foo) ) )))

# Works!



As to why this is the case .


Right. It does seem as though we should need to be deducing the  
inner workings of the subatomic particles by throwing text at the  
interpreter though.


--

David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org 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.


David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org 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] lattice: how to center a subtitle?

2011-04-04 Thread David Scott

 On 05/04/11 13:14, David Winsemius wrote:

On Apr 4, 2011, at 9:03 PM, David Winsemius wrote:


On Apr 4, 2011, at 8:42 PM, David Scott wrote:


On 05/04/11 05:58, David Winsemius wrote:

On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote:


Dear David,

do you know how to get plotmath-like symbols in both rows?
I tried s.th. like:

lab- expression(paste(alpha==1, , , beta==2, sep=))
xlab- substitute(expression( atop(lab==lab., bold(foo)) ),
list(lab.=lab))
xyplot(0 ~ 0, xlab = xlab)

I _did_ have plotmath functions in both rows: But here is your
solution:

xyplot(0 ~ 0,  xlab =
 expression( atop(paste(alpha==1,, beta==2), bold(bla) )) )
   )

Note that `paste` in plotmath is different than `paste` in regular
R.
It has no `sep` argument. I did try both substitute and bquote on
you
externally expression,  but lattice seems to be doing some non-
standard evaluation and I never got it to work. Using what I
thought
_should_ work, does work with `plot`:


  x=1;y=2
  plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y),

bold(foo) ) )
+ )

But the same expression throws an error with xyplot:

  x=1;y=2
  xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y),

bold(foo) ) )
+ )
Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect =
fill,  :
   could not find function atop

I am not sure where I read it and I can't find it again, but my
understanding is that expressions using bquote with lattice need to
be enclosed in as.expression() to work. That is in contrast to what
happens in base graphics.

Perhaps here:
http://finzi.psych.upenn.edu/Rhelp10/2010-August/250832.html


I am pretty sure that was where I saw it. I knew it was out there somewhere.


Or here:
http://finzi.psych.upenn.edu/Rhelp10/2009-July/203714.html

Although I disagree with Heimstra that reading the help(bquote)
provides more details that might shed light on why this is so.



David Scott

--
_
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

__
R-help@r-project.org 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.