[R] ggtern and bquote...

peter dalgaard pdalgd at gmail.com
Mon Dec 4 16:23:38 CET 2017


D'oh! Thanks for pointing this out. I blame caffeine depletion at the time...

-pd

> On 4 Dec 2017, at 15:48 , Eik Vettorazzi <E.Vettorazzi at uke.de> wrote:
> 
> reading ?plotmath you might notice that "_" isn't the propper syntax for
> subscripts. This will work:
> 
> ggtern(data=x11,aes(A,B,C,xend = c(0.7,.00,0.7),yend =
> c(.30,.50,.0),zend =c(.0,.50,0.3)))+
>  geom_point()+
>  theme_showarrows()+geom_segment(size=.5)+
> geom_text_viewport(x=c(.45,.27,.37),y=c(.32,.29,.22),label=c("P[a]","P[b]","P[c]"),
> parse=TRUE)
> 
> cheers.
> 
> Am 04.12.2017 um 15:37 schrieb Levent TERLEMEZ via R-help:
>> Hi,
>> 
>> My example code is this;
>> 
>> x11<-data.frame(A=c(.6,.6,.6),B=c(.20,.20,.20),C=c(0.20,.20,.20))
>> ggtern(data=x11,aes(A,B,C,xend = c(0.7,.00,0.7),yend = c(.30,.50,.0),zend =c(.0,.50,0.3)))+
>>    geom_point()+
>>    theme_showarrows()+geom_segment(size=.5)+
>>    geom_text_viewport(x=c(.45,.27,.37),y=c(.32,.29,.22),label=as.expression("P_a","P_b","P_c"))
>> 
>> ggtern(data=x11,aes(A,B,C,xend = c(0.7,.00,0.7),yend = c(.30,.50,.0),zend =c(.0,.50,0.3)))+
>>    geom_point()+
>>    theme_showarrows()+geom_segment(size=.5)+
>>    geom_text_viewport(x=c(.45,.27,.37),y=c(.32,.29,.22),label=as.expression(quote(c("P_a","P_b","P_c"))))
>> 
>> In geom_text_viewport (I also tried geom_label and geom_text versions) tried all possible solutions, but i couldn't achieved. R command outputs are like this:
>> 
>> Error in stats::complete.cases(df[, vars, drop = FALSE]) :
>>  invalid 'type' (expression) of argument
>> 
>> 
>> Maybe i am writing the code wrong, i couldn't figure out.
>> 
>> Thanks for your kind answers.
>> 
>> 
>> 
>> ________________________________________
>> Kimden: Martin Maechler [maechler at stat.math.ethz.ch]
>> Gönderildi: 04 Aralık 2017 Pazartesi 16:16
>> Kime: peter dalgaard
>> Bilgi: Levent TERLEMEZ; R-help at r-project.org
>> Konu: Re: [R] ggtern and bquote...
>> 
>>>>>>> peter dalgaard <pdalgd at gmail.com>
>>>>>>>    on Mon, 4 Dec 2017 14:55:19 +0100 writes:
>> 
>>>> On 4 Dec 2017, at 11:58 , Levent TERLEMEZ via R-help
>>>> <r-help at r-project.org> wrote:
>>>> 
>>>> Dear Users,
>>>> 
>>>> What is the proper way to write symbol, superscript,
>>>> subscript in ggtern/ggplot? I tried every given example,
>>>> every possible features of ggplot but couldn’t achived. I
>>>> just want to write P_a, sigma^2, etc, would you please
>>>> advise me about this problem.
>> 
>>> Did you try expression(P_a)? I don't do much gg-stuff, but
>>> I seem to recall that quote() doesn't quite cut it the way
>>> it does in base graphics.
>> 
>>> -pd
>> 
>> Yes, I vaguely remember that indeed also for the lattice package
>> (which is based on 'grid' the same as 'ggplot2' is ..) sometimes
>> expressions instead of calls are needed, i.e., expression(*)
>> instead of just quote(*).
>> 
>> However, I think Levent really meant what you'd get by
>> expression(P[a]) ?
>> 
>> @Levent: The clue is the need for valid R syntax, and indeed, as
>>   in LaTeX  x_i often is the i-th element of x,  the R syntax for
>>   indexing/subsetting is used here, i.e.
>>    x[i]  for LaTeX  x_i
>> 
>> 
>> Last but not least, if Levent really needs bquote() [i.e. substitute()]
>> then, a final
>>      as.expression(.)
>> may be needed :
>> 
>> identical(as.expression(quote(a == 1)),
>>             expression(      a == 1))  # --> TRUE
>> 
>> --
>> Martin Maechler, ETH Zurich
>> 
>> 
>> ________________________________
>> 
>> Bu elektronik posta ve onunla iletilen bütün dosyalar sadece yukarıda isimleri belirtilen kişiler arasında özel haberleşme amacını taşımakta olup gönderici tarafından alınması amaçlanan yetkili gerçek ya da tüzel kişinin kullanımına aittir. Eğer bu elektronik posta size yanlışlıkla ulaşmışsa, elektronik postanın içeriğini açıklamanız, kopyalamanız, yönlendirmeniz ve kullanmanız kesinlikle yasaktır. Bu durumda, lütfen mesajı geri gönderiniz ve sisteminizden siliniz. Anadolu Üniversitesi bu mesajın içerdiği bilgilerin doğruluğu veya eksiksiz olduğu konusunda herhangi bir garanti vermemektedir. Bu nedenle bu bilgilerin ne şekilde olursa olsun içeriğinden, iletilmesinden, alınmasından ve saklanmasından sorumlu değildir. Bu mesajdaki görüşler yalnızca gönderen kişiye aittir ve Anadolu Üniversitesinin görüşlerini yansıtmayabilir.
>> 
>> This electronic mail and any files transmitted with it are intended for the private use of the people named above. If you are not the intended recipient and received this message in error, forwarding, copying or use of any of the information is strictly prohibited. Any dissemination or use of this information by a person other than the intended recipient is unauthorized and may be illegal. In this case, please immediately notify the sender and delete it from your system. Anadolu University does not guarantee the accuracy or completeness of any information included in this message. Therefore, by any means Anadolu University is not responsible for the content of the message, and the transmission, reception, storage, and use of the information. The opinions expressed in this message only belong to the sender of it and may not reflect the opinions of Anadolu University.
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>> 
> 
> -- 
> Eik Vettorazzi
> 
> Department of Medical Biometry and Epidemiology
> University Medical Center Hamburg-Eppendorf
> 
> Martinistrasse 52
> building W 34
> 20246 Hamburg
> 
> Phone: +49 (0) 40 7410 - 58243
> Fax:   +49 (0) 40 7410 - 57790
> Web: www.uke.de/imbe
> --
> 
> _____________________________________________________________________
> 
> Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg | www.uke.de
> Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe Koch-Gromus, Joachim Prölß, Martina Saurin (komm.)
> _____________________________________________________________________
> 
> SAVE PAPER - THINK BEFORE PRINTING
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list