latex2exp包的vignettes
- 利用
latex2exp
包中的TeX函数,在基础绘图和ggplot2中使用LaTeX数学公式 \sum
、\beta
等以反斜杠开始的符号,在TeX函数中需写为\\sum
、\\beta
基础绘图
library(latex2exp)
library(ggplot2)
par(pin = c(4, 3), mai = c(1, 1, 1, 1)) # 控制绘图区域
plot(x = c(0, 1), y = c(0, 1),
xlab = TeX("$\\sum_{i=1}{n}$"),
ylab = TeX("$y=e^{\\beta}$"),
main = TeX("$\\frac{a}{b}$"))
text(0.5, 0.5, TeX("$\\sqrt{2}$"))
ggplot2
ggplot() +
geom_point() +
labs(x = TeX("$\\sum_{i=1}{n}$"),
y = TeX("$y=e^{\\beta}$"),
title = TeX("$\\frac{a}{b}$")) +
annotate(geom = "text", x = 1, y = 1,
label = TeX("$\\sqrt{2}$")) +
theme_classic() +
theme(axis.text = element_blank(),
axis.ticks = element_blank()) # 去除坐标轴刻度和刻度标签