[R] depth of labels of axis
David Winsemius
dwinsemius at comcast.net
Sat Sep 6 02:04:18 CEST 2014
On Sep 5, 2014, at 4:53 PM, David Winsemius wrote:
>
> On Sep 5, 2014, at 4:15 PM, Jinsong Zhao wrote:
>
>> On 2014/9/4 14:58, David L Carlson wrote:
>>> The problem with this approach is that the horizontal positioning of the labels is based on the width of the label including the phantom part so that the E's are pushed to the left of the tick mark (at least on my Windows machine). But it does provide a way of dealing with superscripts as long as the phantom is added to each label and hadj= is used to position the label horizontally, eg (changing the last label to a superscript for illustration):
>>>
>>> lbl <- expression(E[g]~phantom(E[g]), E~phantom(E[g]), E[j]~phantom(E[g]),
>>> E~phantom(E[g]), E^t~phantom(E[g]))
>>> plot(1:5, xaxt = "n")
>>> axis(1, at = 1:5, labels = lbl, hadj=.1)
>>> abline(h=.7, xpd=TRUE, lty=3)
>>>
>>> David C
>>
>> Yes, it works well. However, we have to adjust the hadj with our eyes.
>>
>> I hope the TODO wish can be implemented in the nearly future.
>
> Man, this is a really hard crowd to please. Consider this use of the c(expression(),...) "trick" and the appending of super and subscripts to every item fore and aft (sailing terminology):
>
> updown <- function(x){ e <- expression(); return(c(e,sapply( x, function(x) bquote( phantom(E)^phantom(t)*.(x)*phantom(E)[phantom(g)] , list(x=x)) ))) }
There is an extraneous list(x=x) left over from when I was trying to use substitute() that should be removed, although it didn't seem to affect the output..
>
> lbl <- expression(E[g], E, E[j], E, E^t)
>
> plot(1:5, xaxt = "n")
> axis(1, at = 1:5, labels = updown(lbl) )
> abline(h=.7, xpd=TRUE, lty=3)
>
>
>
>>
>> Thanks a lot.
>>
>> Best regards,
>> Jinsong
>>
>>
>>>
>>> -----Original Message-----
>>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of David Winsemius
>>> Sent: Thursday, September 4, 2014 2:25 PM
>>> To: Jinsong Zhao
>>> Cc: r-help at r-project.org
>>> Subject: Re: [R] depth of labels of axis
>>>
>>>
>>> On Sep 3, 2014, at 10:05 PM, Jinsong Zhao wrote:
>>>
>>>> On 2014/9/3 21:33, Jinsong Zhao wrote:
>>>>> On 2014/9/2 11:50, David L Carlson wrote:
>>>>>> The bottom of the expression is set by the lowest character (which can
>>>>>> even change for subscripted letters with descenders. The solution is
>>>>>> to get axis() to align the tops of the axis labels and move the line
>>>>>> up to reduce the space, e.g.
>>>>>>
>>>>>> plot(1:5, xaxt = "n")
>>>>>> axis(1, at = 1:5, labels = c(expression(E[g]), "E", expression(E[j]),
>>>>>> "E", expression(E[t])), padj=1, mgp=c(3, .1, 0))
>>>>>> # Check alignment
>>>>>> abline(h=.7, xpd=TRUE, lty=3)
>>>>>
>>>>> yes. In this situation, padj = 1 is the fast solution. However, If there
>>>>> are also superscript, then it's hard to alignment all the labels.
>>>>>
>>>>> If R provide a mechanism that aligns the label in axis() or text() with
>>>>> the baseline of the character without the super- and/or sub-script, that
>>>>> will be terrific.
>>>>
>>>> it seems that the above wish is on the Graphics TODO lists:
>>>> https://www.stat.auckland.ac.nz/~paul/R/graphicstodos.html
>>>>
>>>> Allow text adjustment for mathematical annotations which is relative to a text baseline (in addition to the current situation where adjustment is relative to the bounding box).
>>>>
>>>
>>> In many case adding a phantom argument will correct aliognment problems:
>>>
>>> plot(1:5, xaxt = "n")
>>> axis(1, at = 1:5, labels = c(expression(E[g]), E~phantom(E[g]), expression(E[j]),
>>> E~phantom(E[g]), expression(E[t])))
>>>
>>> abline(h=.7, xpd=TRUE, lty=3)
>>>
>>> Notice that c(expression(.), ...) will coerce all items separated by commas to expressions, sot you cna just put in "native" expression that are not surrounded by the `expression`-function
>>>
>>> c(expression(E[g]), E~phantom(E[g]), expression(E[j]) ) #returns
>>> # expression(E[g], E ~ phantom(E[g]), E[j])
>>>
>>> The tilde is actually a function that converts parse-able strings into R language objects:
>>>
>>> c(expression(E[g]), E~phantom(E[g]), ~E[j])
>>>
>>
>> ______________________________________________
>> 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
> Alameda, CA, USA
>
> ______________________________________________
> 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
Alameda, CA, USA
More information about the R-help
mailing list