Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notation for fractions (divides by or over) in R and ggplot2

Tags:

r

ggplot2

I am trying to place one word over another for a title. I mean literally over, not just a 'divides by' sign one value over another (or word) to save space. It is supposed to mean divides by and there needs to be a line.

I cannot find how to do this, can you help?

Thanks,

Chris

like image 678
Christopher John Avatar asked Dec 06 '16 11:12

Christopher John


1 Answers

You can create fractions in a title with frac():

p <- ggplot(mtcars, aes(x = mpg, y = disp)) + geom_point()
p + ggtitle(expression(paste("This is a fraction: ", frac(foo, bar))))

enter image description here

Note that the whole title must be put inside expression(). Alternatively, you can also use over() to do the same. The following example also shows that you can create other mathematical expressions in a similar fashion:

p + ggtitle(expression(paste("This is a fraction: ", over(3 * alpha, sum(b[i], i==1, N)))))

enter image description here

For more information, read ?plotmath.

like image 153
Stibu Avatar answered Nov 14 '22 23:11

Stibu