`sep =` 作为分隔符的语法
Syntax of `sep =` as separator
我想了解命令的语法 sep =
。下面,我报告一个示例代码:
library(ggpmisc)
library(ggplot2)
formula <- y ~ x + I(x^2)
ggplot(cars, aes(speed, dist)) +
geom_point() +
stat_fit_deviations(formula = formula, colour = "red") +
stat_poly_line(formula = formula) +
stat_poly_eq(aes(label = paste(stat(eq.label), stat(adj.rr.label), sep = "*\", \"*")),
formula = formula)
我了解到sep = "*\", \"*"
的目的是在eq.label
和adj.rr.label
之间添加一个逗号。 stat_poly_eq
的指南上没有参考,我想了解"*\"
和\"*"
的意思,也许可以学习更多的东西来改变这个配置。
您在stat_poly_eq
中创建的标签是字符串。它们被解析为表达式,而表达式又被转换为 plotmath 符号。您可以通过以下方式了解它的工作原理:
plot(1:10, type = 'n')
text(5, 5, label = expression(paste(y~`=`~3*italic(x)^2*", "*R^2)))
所有 sep
在您的情况下所做的是在公式和 R 平方之间提供一个分隔逗号和 space。只要它正确解析为有效的 plotmath 表达式,您就可以将其更改为您喜欢的任何内容:
formula <- y ~ x + I(x^2)
ggplot(cars, aes(speed, dist)) +
geom_point() +
stat_fit_deviations(formula = formula, colour = "red") +
stat_poly_line(formula = formula) +
stat_poly_eq(aes(label = paste(stat(eq.label), stat(adj.rr.label),
sep = "*\" is the formula, and the R squared is \"*")),
formula = formula)
请参阅 ?plotmath
了解您可以使用 plotmath 表达式做的所有事情
我想了解命令的语法 sep =
。下面,我报告一个示例代码:
library(ggpmisc)
library(ggplot2)
formula <- y ~ x + I(x^2)
ggplot(cars, aes(speed, dist)) +
geom_point() +
stat_fit_deviations(formula = formula, colour = "red") +
stat_poly_line(formula = formula) +
stat_poly_eq(aes(label = paste(stat(eq.label), stat(adj.rr.label), sep = "*\", \"*")),
formula = formula)
我了解到sep = "*\", \"*"
的目的是在eq.label
和adj.rr.label
之间添加一个逗号。 stat_poly_eq
的指南上没有参考,我想了解"*\"
和\"*"
的意思,也许可以学习更多的东西来改变这个配置。
您在stat_poly_eq
中创建的标签是字符串。它们被解析为表达式,而表达式又被转换为 plotmath 符号。您可以通过以下方式了解它的工作原理:
plot(1:10, type = 'n')
text(5, 5, label = expression(paste(y~`=`~3*italic(x)^2*", "*R^2)))
所有 sep
在您的情况下所做的是在公式和 R 平方之间提供一个分隔逗号和 space。只要它正确解析为有效的 plotmath 表达式,您就可以将其更改为您喜欢的任何内容:
formula <- y ~ x + I(x^2)
ggplot(cars, aes(speed, dist)) +
geom_point() +
stat_fit_deviations(formula = formula, colour = "red") +
stat_poly_line(formula = formula) +
stat_poly_eq(aes(label = paste(stat(eq.label), stat(adj.rr.label),
sep = "*\" is the formula, and the R squared is \"*")),
formula = formula)
请参阅 ?plotmath
了解您可以使用 plotmath 表达式做的所有事情