[R] \n and italic() in legend()

Duncan Mackay dulcalma at bigpond.com
Thu Dec 29 23:56:09 CET 2016


Hi Marc

I forgot about the other things than atop in my reply. Others seem to have
exhausted base graphics options
Could using grid.text solve your problems ?

e.g. Guide code

plot(1,1)

grid.clip()

vp <- viewport(width = 1, height = 1)
    
 pushViewport(vp)

grid.text( "text", 0.25,0.25)
popViewport(0)

Regards

Duncan

-----Original Message-----
From: Marc Girondot [mailto:marc_grt at yahoo.fr] 
Sent: Friday, 30 December 2016 08:46
To: Duncan Mackay; wjm1 at caa.columbia.edu; R-help Mailing List
Subject: Re: [R] \n and italic() in legend()

Hi,
Thanks a lot to Duncan Mackay for the trick using atop() [but the 
legends are centered and not left aligned] and also for the suggestion 
of William Michels to use simply ",". However this last solution 
prevents to use several legends.

Here is a solution to allow both return within a legend and several legends:
plot(1, 1)
v1 <- c(expression(italic("p")*"-value"), expression("based on 
"*italic("t")*"-test"))
v2 <- c(expression(italic("w")*"-value for A"), expression("and B 
identical models"))
legend("topright", legend=c(v1, v2), lty=c(1, 0, 1, 0), y.intersp = 1, 
bty="n", col=c("black", "", "red", ""))

Thanks again

Marc


Le 29/12/2016 à 10:54, Duncan Mackay a écrit :
> Hi Marc
>
> Try atop
>
> plot(1, 1)
> v1 <- expression(atop(italic("p")*"-value","based on
"*italic("t")*"-test"))
> legend("topright", legend=v1, y.intersp = 3, bty="n")
>
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mackay at northnet.com.au
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Marc
> Girondot via R-help
> Sent: Thursday, 29 December 2016 20:35
> To: R-help Mailing List
> Subject: [R] \n and italic() in legend()
>
> Hi everyone,
>
> Could someone help me to get both \n (return) and italic() in a legend.
> Here is a little example showing what I would like (but without the
> italic) and second what I get:
>
> plot(1, 1)
> v1 <- "p-value\nbased on t-test"
> legend("topright", legend=v1, y.intersp = 3, bty="n")
>
> plot(1, 1)
> v1 <- expression(italic("p")*"-value\nbased on "*italic("t")*"-test")
> legend("topright", legend=v1, y.intersp = 3, bty="n")
>
> The second one shows :
>
> -value
> pbased on t-test
>
> rather than the expected:
>
> p-value
> based on t-test
>
> Thanks a lot,
>
> Marc
>
> ______________________________________________
> 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.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list