[R] Paste symbol and calculation in plot
Scott Sherrill-Mix
shescott at mail.med.upenn.edu
Tue Aug 11 23:18:18 CEST 2009
I'm no expert at this but it seems like ?plotmath is saying to do
something like:
text(2,0.35,bquote(sigma==.(mySigma),list('mySigma'=round(sd(Data),digits=3))))
Scott
Scott Sherrill-Mix
Department of Microbiology
University of Pennsylvania
402B Johnson Pavilion
3610 Hamilton Walk
Philadelphia, PA 19104-6076
On Tue, Aug 11, 2009 at 4:00 PM, Jonathan R.
Blaufuss<blaufusj at carleton.edu> wrote:
> I'm trying to annotate a density plot and I would like to have R calculate the
> standard deviation and place it in the plot next to the standard deviation symbol
> "sigma". I can successfully use the text command to paste "StDev =",round(sd(Data),digits=3))
> on the plot. However, I have trouble when I want to replace "StDev" with the Greek
> symbol sigma (See code below).
>
> set.seed(1)
> Data=rnorm(100)
> plot(density(Data))
> text(2,0.35,paste("StDev =",round(sd(Data),digits=3)))
>
> Through searching the help files I figured out that I can paste the sigma symbol on the
> plot using the command "expression".
>
> text(2,0.3,expression(paste(sigma," = 0.898")))
>
> However, when I try to paste together the sigma symbol and the standard deviation
> that R is calculating, the text of the command to calculate the standard deviation
> shows up on the plot instead of the number which I am asking it to calculate.
>
> text(2.2,0.25,expression(paste(sigma," = ",round(sd(Data),digits=3))))
>
> Can someone please point me to a resource that will help me figure this out?
>
> Thank You,
>
> Jonathan
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list