我目前正在尝试向我的 ggplot 添加注释,该注释以我提供的图像中显示的特定格式显示分数
1/9
。尽管这看起来是一项简单的任务,但我发现自己陷入困境,无法找出完成此任务的正确方法。任何有关如何实现这一目标的指导将不胜感激。
这是一个例子:
ggplot(mtcars, aes(cyl, mpg)) +
geom_point()+
annotate("text", x = 3, y = 3, label = "1/9", size = 10, color = "red") +
coord_cartesian()
添加分数的一个选项是使用
?plotmath
:
library(ggplot2)
ggplot(mtcars, aes(cyl, mpg)) +
geom_point() +
annotate("text",
x = 5, y = 30, label = "frac(1, 9)", size = 10, color = "red",
parse = TRUE
) +
coord_cartesian()