Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mtext() in R plot

Tags:

plot

r

I was wondering what's wrong with mtext() that I can't get the number G correctly show above my plot?

Here is my R code:

G <- .3333 ## but G can be anything as it comes from a function

curve(dnorm(x),-3,3)
mtext(expression(paste("Medium: ",bold('CT'[12])," = ", round(G,2))),line=3)
like image 333
rnorouzian Avatar asked Aug 10 '26 21:08

rnorouzian


1 Answers

You can use bquote and .() (this is used to include variables in an expression) for this:

G <- 0.3333
curve(dnorm(x),-3,3)
mtext(bquote(paste("Medium: ",bold('CT'[12])," = ", .(round(G,3)))),line=3)

This gives:

enter image description here

like image 131
LyzandeR Avatar answered Aug 13 '26 10:08

LyzandeR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!