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

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Mon, 04 Apr 2011 21:14:40 -0400

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_at_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_at_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.
Received on Tue 05 Apr 2011 - 01:17:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 05 Apr 2011 - 02:40:26 GMT.

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

list of date sections of archive