Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R plot title with greek letter, newline and variable value

I am trying to plot a title, a greek character and as well the mean of a variable. I want my plot title to look something like this (but centered)

Title

μ=1.2

I made a few attepmts:

d <- rnorm(100)
hist(d, main=expression(paste("Title\n", mu, "=", mean(d))))
hist(d, main=expression(paste("Title\n", mu, "=", mymean), list(mymean=mean(d))))
hist(d, main=paste(expression(paste("Title\n", mu, "="), mean(d))))
hist(d, main=expression(atop("Title", substitute(mu, "=", mymean, list(mymean=mean(d))))))
hist(d, main=expression("Title\n", substitute(mu, "=", mymean, list(mymean=mean(d)))))

but I don't know how to use expression or substitute correctly in the title. I know that mtext would be a possibility, but it should work using the main= argument...?

like image 813
user1981275 Avatar asked Dec 21 '22 07:12

user1981275


1 Answers

You can do this with atop:

hist(d, main=bquote(atop(Title,mu==.(mean(d)))))

enter image description here

like image 128
Julián Urbano Avatar answered Jan 11 '23 23:01

Julián Urbano