gpt4 book ai didi

r - R中传说中的希腊字母

转载 作者:行者123 更新时间:2023-12-04 00:32:01 24 4
gpt4 key购买 nike

我想在同一个图上有三个不同参数 alpha 的曲线。

curve(sin(x), from = 1, to = 3, lty = 1, ylim = c(-1, 1))
curve(sin(2 * x), add = TRUE, lty = 2)
curve(sin(3 * x), add = TRUE, lty = 3)
legend("topright", legend = expression(paste(alpha, " = ", c(1, 2, 3))), lty = 1:3)

在图例中,我想要三行 alplha = 1, alpha = 2, alpha = 3. 我如何使它正确?
enter image description here

最佳答案

更好的循环答案来自 here和用户 20650。

用 sapply 解决方案
expression功能相当棘手,但与 substitute 一起使用您可以使用 sapply循环:

curve(sin(x), from = 1, to = 3, lty = 1, ylim = c(-1, 1))
curve(sin(2 * x), add = TRUE, lty = 2)
curve(sin(3 * x), add = TRUE, lty = 3)
legend("topright",
legend = sapply(1:3, function(x) as.expression(substitute(alpha == B,
list(B = as.name(x))))),
lty = 1:3)

简单修复
curve(sin(x), from = 1, to = 3, lty = 1, ylim = c(-1, 1))
curve(sin(2 * x), add = TRUE, lty = 2)
curve(sin(3 * x), add = TRUE, lty = 3)
legend("topright", legend = c(expression(paste(alpha, " = ", 1)),
expression(paste(alpha, " = ", 2)),
expression(paste(alpha, " = ", 3))), lty = 1:3)

关于r - R中传说中的希腊字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30540028/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com