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

Duncan Mackay dulcalma at bigpond.com
Thu Dec 29 10:54:07 CET 2016

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")



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 :

pbased on t-test

rather than the expected:

based on t-test

Thanks a lot,


R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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