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

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Mon, 04 Apr 2011 15:03:44 -0300

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 <dwinsemius_at_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_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help