- 已编辑
substitute
函数可以用来替换表达式,这个作用之一就是参数不同时,批量地画函数图像,而且在坐标轴标签或者 title 部分给出函数表达式
# 方法4
plot(y1 ~ x1,
data = anscombe,
xlab = substitute(x[i], list(i = 1)),
ylab = substitute(expression(y[i]), list(i = 1))
)
我知道有种更加简洁的方式,但是为了能够不把 xlab 写死,就需要 substitute
函数
# 方法3
plot(y1~x1,
data = anscombe,
xlab = expression(x[1]),
ylab = expression(y[1])
)
ps
# 方法1
plot(y1 ~ x1,
data = anscombe,
xlab = substitute(x[i], list(i = 1)),
ylab = substitute(y[i], list(i = 1))
)
和
# 方法2
plot(y1 ~ x1,
data = anscombe,
xlab = substitute(expression(x[i]), list(i = i)),
ylab = substitute(expression(y[i]), list(i = i))
)
都不对
sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936
[2] LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0