如何用分子和分母垂直对齐并用水平线分隔来注释除法

问题描述 投票:0回答:1

我目前正在尝试向我的 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()

r ggplot2 annotations division
1个回答
0
投票

添加分数的一个选项是使用

?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()

© www.soinside.com 2019 - 2024. All rights reserved.