我想使用该annotate()函数将以下等式放入R中的ggplot中.
我似乎能够到目前为止最接近的是以下内容
ggplot()+ annotate("label", x = 1, y = 1, label = "APC == 0.50 ~ Depth ^ {-0.99} * (Cone == 0~Net == 1) ^ {0.59}", parse = TRUE, size = 5)
Run Code Online (Sandbox Code Playgroud)
这很好,但能够从等式中添加*和|符号会很好.我尝试了以下方法:
ggplot()+ annotate("label", x = 1, y = 1, label = "APC == 0.50 * Depth ^ {-0.99} * (Cone == 0|Net == 1) ^ {0.59}", parse = TRUE, size = 5)
Run Code Online (Sandbox Code Playgroud)
但它最终看起来很奇怪
关于如何添加or和星形符号的任何建议?
如果有人可以向我解释|当我尝试使用符号时实际发生了什么,为什么它出现在它的位置并添加括号和逗号?
另一种方法是使用LaTeX表达式 latex2exp::TeX
library(ggplot2)
library(latex2exp)
ggplot() +
annotate(
"label",
x = 1, y = 1,
label = TeX("$APC = 0.50 \\times Depth^{-0.99} \\times (Cone = 0 | Net = 1)^{0.59}$"),
size = 5)
Run Code Online (Sandbox Code Playgroud)
另外两条评论:
latex2exp支持一些 LaTeX表达式但不是全部.例如,在LaTeX中\vert并且|是同义词,但latex2exp正确排版时|它会失败\vert.该latex2exp小品有一个包含支持LaTeX的表情列表的部分"支持的LaTeX". latex2exp::TeX需要使用额外的反斜杠为所有LaTeX命令添加前缀(转义).因此\times变得\\times.| 归档时间: |
|
| 查看次数: |
92 次 |
| 最近记录: |