Notation for fractions (divides by or over) in R a

2019-07-11 14:28发布

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

标签: r ggplot2
1条回答
淡お忘
2楼-- · 2019-07-11 15:05

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.

查看更多
登录 后发表回答