[R] Superscript in graph text

Jake William Andrae jake.andrae at adelaide.edu.au
Thu Jan 19 03:48:06 CET 2017


Thank you, your suggestions are very helpful. As I said, I'm a novice to R and this list, and it's hard for me to decipher exactly what is required; I was really hoping for some basic script formatting guidance (which was given and appreciated).


Jake Andrae
PhD Candidate
Geology & Geophysics – Sprigg Geobiology Centre
Department of Earth Science
School of Physical Sciences
The University of Adelaide, AUSTRALIA 5005
Phone: 0407701565
Email: jake.andrae at adelaide.edu.au



________________________________
From: Richard M. Heiberger <rmh at temple.edu>
Sent: Thursday, 19 January 2017 12:58 PM
To: Jake William Andrae
Subject: Re: [R] Superscript in graph text

your example is not reproducible because I don't have your dataset.
Please re-read the notes
at the bottom of every R-help email
   PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.

The convention on this email list is to always stay on the list.  It
is not good form to
write only to the person who replies to you and the list.

For base graphics, you can use an expression or bquote in any of the
annotation arguments or functions.
I showed you a use in main=.  It works the same for all others.



plot(1:10)
p <- .4
R2 <- .9876
mtext(bquote(p * " = " * .(p)), adj=0, line=0.1, col="black", cex=0.7)
mtext(bquote(R^2 * " =" * .(R2)), adj=0, line=1, col="black", cex=0.7)

## Using mtext doesn't look like a good idea.
## use sub or main or some other keywords

title(main=bquote(p * " = " * .(p)),
      sub=bquote(R^2 * "/" * p * " = " * .(R2/p)))

## Or do it all together
p <- .4
R2 <- .9876
plot(1:10,
     main=bquote(p * " = " * .(p)),
     sub=bquote(R^2 * "/" * p * " = " * .(R2/p)),
     xlab=bquote(R^2 * " = " * .(R2)),
     ylab=expression(e^(-z^2))
     )

## at some point, soon I recommend, you should learn either lattice or ggplot.
## you might also want to look at the archives of R-SIG-Geo,start with
https://www.r-project.org/mail.html

## Please Keep the list in further emails

On Wed, Jan 18, 2017 at 8:09 PM, Jake William Andrae
<jake.andrae at adelaide.edu.au> wrote:
> Hi Richard,
>
>
> If I want to use the ?plotmath function, how would I go about writing that
> into the script I have for my graphs?
>
> I've just pasted the whole script here, with the summary label section
> higlighted. Sorry to be a burden like this, I'm a real novice to R haha.
>
>
> #Concentration
> plot(Annual_precipitation, Concentration, xaxs = "i", yaxs = "i", xlim =
> c(1000, 2400), ylim = c(0,500), xlab = NA, ylab = "Concentration", xaxt='n',
> pch=21,  bg='black',
> rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = "gray"))
> par(xpd=FALSE)
> abline(lm(Concentration~Annual_precipitation))
> par(xpd=NA)
> AnnualPrecipitationConcentration <- lm(Concentration~Annual_precipitation)
>         #Summary labels
>         R2 <- round(summary(AnnualPrecipitationConcentration)$r.squared, 2)
>         p <- anova(AnnualPrecipitationConcentration)[1,5]
>         if(p <= 0.001){
>         p <- "< 0.001"
>         }else{p <- round(p, 3)}
>         x <- 10
>         mtext(paste("R2 = ", R2), adj=0, line=1, col="black", cex=0.7)
>         mtext(paste("p = ", p), adj=0, line=0.1, col="black", cex=0.7)
>
>
> Kind regards,
>
> Jake
>
>
>
> Jake Andrae
> PhD Candidate
> Geology & Geophysics – Sprigg Geobiology Centre
> Department of Earth Science
> School of Physical Sciences
> The University of Adelaide, AUSTRALIA 5005
> Phone: 0407701565
> Email: jake.andrae at adelaide.edu.au
>
> ________________________________
> From: Richard M. Heiberger <rmh at temple.edu>
> Sent: Thursday, 19 January 2017 11:30:38 AM
> To: Jake William Andrae
> Cc: r-help at r-project.org
> Subject: Re: [R] Superscript in graph text
>
> x <- 10
> plot(1:10, main=bquote(R^2 * "=" * .(x)))
>
> On Wed, Jan 18, 2017 at 8:00 PM, Richard M. Heiberger <rmh at temple.edu>
> wrote:
>> ?plotmath
>>
>>
>> plot(1:10, main=expression(R^2))
>>
>> plot(1:10, main=bquote(R^2 * "=" * .(x)))
>>
>> On Wed, Jan 18, 2017 at 7:44 PM, Jake William Andrae
>> <jake.andrae at adelaide.edu.au> wrote:
>>> Hello,
>>>
>>>
>>> I've added some statistical information as text to some graphs, but I'm
>>> having a really hard time making the 2 in the R2 label superscript. Does
>>> anyone have any suggestions?
>>>
>>>
>>> mtext(paste("R2 = ", R2), adj=0, line=1, col="black", cex=0.7)
>>>
>>>
>>> Kind regards
>>>
>>>
>>> Jake Andrae
>>> PhD Candidate
>>> Geology & Geophysics - Sprigg Geobiology Centre
>>> Department of Earth Science
>>> School of Physical Sciences
>>> The University of Adelaide, AUSTRALIA 5005
>>> Phone: 0407701565
>>> Email: jake.andrae at adelaide.edu.au
>>>
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
R-help Info Page - Homepage - SfS – Seminar for Statistics<https://stat.ethz.ch/mailman/listinfo/r-help>
stat.ethz.ch
The main R mailing list, for announcements about the development of R and the availability of new code, questions and answers about problems and solutions using R ...


>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]



More information about the R-help mailing list