Re: [R] LaTeX in R

From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>
Date: Fri, 07 Mar 2008 08:22:26 -0800

Or my personal favorite if the length of mySigma is variable:

mySigma <- 2:3
plot(1:10, dnorm(1:10, sd = mySigma[1]), type = 'l') lines(dnorm(1:10,sd = mySigma[2]),lty = 2) leg <- as.expression(lapply(mySigma, function(x) bquote(sigma == .(x)))) legend(x = "topright", lty = c(1,2),legend = leg)

Thanks,

--sundar

Uwe Ligges said the following on 3/7/2008 8:15 AM:
> You might want to read
> Ligges, U. (2002): R Help Desk: Automation of Mathematical Annotation
> in Plots. R News 2 (3), 32-34.
> with an example at the end that meets your requirements:
>
> (please note that I removed those ugly ";"
>
>
> mySigma[1] <- 2
> mySigma[2] <- 3
> plot(1:10, dnorm(1:10, sd = mySigma[1]), type = 'l')
> lines(dnorm(1:10, sd = mySigma[2]), lty = 2)
> legend1 <- substitute(sigma == myS, list(myS = mySigma[1]))
> legend2 <- substitute(sigma == myS, list(myS = mySigma[2]))
> legend(x = "topright", lty = c(1,2),
> legend = do.call(expression, list(legend1, legend2)))
>
>
> Uwe Ligges
>
>
>
> Mario Maiworm wrote:

>> Finally, this should work for an array of sigmas. I just realized that the
>> substitute()-command is not evaluated within a c()-environment :(
>>
>> mySigma[1] <- 2; mySigma[2] <- 3;
>> plot(1:10, dnorm(1:10, sd = mySigma[1]), type = 'l') ;
>> lines(dnorm(1:10,sd = mySigma[2]),lty = 2);
>> legend(x = "topright", lty = c(1,2),legend = c(substitute(sigma == myS,
>> list(myS = mySigma[1])),substitute(sigma == myS, list(myS = mySigma[2]))))
>>
>> Mario.
>>
>>  
>> __________________________________________________________________
>>
>> Mario Maiworm
>> Biological Psychology and Neuropsychology
>> University of Hamburg
>> Von-Melle-Park 11
>> D-20146 Hamburg
>>
>> Tel.: +49 40 42838 3515
>> Fax.: +49 40 42838 6591
>>
>> http://bpn.uni-hamburg.de/Maiworm_e.html
>> http://cinacs.org
>> __________________________________________________________________
>>
>>>>> -----Ursprüngliche Nachricht-----
>>>>> Von: Uwe Ligges [mailto:ligges_at_statistik.tu-dortmund.de]
>>>>> Gesendet: Freitag, 7. März 2008 16:30
>>>>> An: Mario Maiworm
>>>>> Cc: r-help_at_r-project.org
>>>>> Betreff: Re: AW: [R] LaTeX in R
>>>>>
>>>>>
>>>>>
>>>>> Mario Maiworm wrote:
>>>>>> Thank you, uwe and jeremy. I was actually looking exactly for that!
>>>>> But
>>>>>> something still doesn't work:
>>>>>> I want to plot a symbol in a legend of a plot, lets say "\sigma = 2".
>>>>> 2
>>>>>> should be the value of a variable. So, when I try
>>>>>>
>>>>>> mySigma=2;plot(1:10,dnorm(1:10,sd=mySigma),type='l')
>>>>>> legend(x="topright",legend=paste(expression(sigma)," =
>>>>> ",mySigma),lty=1)
>>>>>> , the sigma is not plotted as a symbol. This version:
>>>>>>
>>>>>> mySigma=2;plot(1:10,dnorm(1:10,sd=mySigma),type='l')
>>>>>> legend(x="topright",legend=expression(paste(sigma," =
>>>>> ",mySigma)),lty=1)
>>>>>> gives me a 'real' sigma but the mySigma variable is not evaluated. Any
>>>>>> ideas?
>>>>> Yes:
>>>>>
>>>>>
>>>>> mySigma <- 2
>>>>> plot(1:10, dnorm(1:10, sd = mySigma), type='l')
>>>>> legend(x = "topright", lty = 1,
>>>>>         legend = substitute(sigma == myS, list(myS = mySigma)))
>>>>>
>>>>>
>>>>> Uwe Ligges
>>>>>
>>>>>
>>>>>> Mario.
>>>>>>
>>>>>> __________________________________________________________________
>>>>>>
>>>>>> Mario Maiworm
>>>>>> Biological Psychology and Neuropsychology
>>>>>> University of Hamburg
>>>>>> Von-Melle-Park 11
>>>>>> D-20146 Hamburg
>>>>>>
>>>>>> Tel.: +49 40 42838 3515
>>>>>> Fax.: +49 40 42838 6591
>>>>>>
>>>>>> http://bpn.uni-hamburg.de/Maiworm_e.html
>>>>>> http://cinacs.org
>>>>>> __________________________________________________________________
>>>>>>
>>>>>>>>> -----Ursprüngliche Nachricht-----
>>>>>>>>> Von: Uwe Ligges [mailto:ligges_at_statistik.tu-dortmund.de]
>>>>>>>>> Gesendet: Freitag, 7. März 2008 15:27
>>>>>>>>> An: Mario Maiworm
>>>>>>>>> Cc: r-help_at_r-project.org
>>>>>>>>> Betreff: Re: [R] LaTeX in R
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Mario Maiworm wrote:
>>>>>>>>>> Dear Rers,
>>>>>>>>>> I understand that I can include R-code in LaTeX using Sweave. Is
>>>>> there
>>>>>>>>> a way
>>>>>>>>>> to do it the other way round? Particularly, I need some TeX
>>>>> symbols in
>>>>>>>>> the
>>>>>>>>>> legend of an R-plot. This can be done in matlab easily, so I am
>>>>>>>>> optimistic
>>>>>>>>>> with R. Any suggestions for a command or package?
>>>>>>>>> See   ?plotmath
>>>>>>>>>
>>>>>>>>> Uwe Ligges
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> Best,
>>>>>>>>>> Mario.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> __________________________________________________________________
>>>>>>>>>>
>>>>>>>>>> Mario Maiworm
>>>>>>>>>> Biological Psychology and Neuropsychology
>>>>>>>>>> University of Hamburg
>>>>>>>>>> Von-Melle-Park 11
>>>>>>>>>> D-20146 Hamburg
>>>>>>>>>>
>>>>>>>>>> Tel.: +49 40 42838 3515
>>>>>>>>>> Fax.: +49 40 42838 6591
>>>>>>>>>>
>>>>>>>>>> http://bpn.uni-hamburg.de/Maiworm_e.html
>>>>>>>>>> http://cinacs.org
>>>>>>>>>>
>>>>>>>>>> ______________________________________________
>>>>>>>>>> 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.

>
> ______________________________________________
> 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.


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 Fri 07 Mar 2008 - 16:31:55 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 Fri 07 Mar 2008 - 18:30:20 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