在 R 中的绘图等式中包含逗号
Including comma in equation on plot in R
我想在使用 ggplot2 创建的图形上打印线性回归的 F 统计量和 df。我已经非常接近了,但我似乎无法在自由度(1 和 8)之间出现逗号。
#generate some data
x <- 1:10
y <- 1:10 + rnorm(10, 0.1, 0.2)
#run linear regression
mod1 <- lm(y~x)
#get r2 and df and round for better printing
Fstat <- round(summary(mod1)$fstatistic, 3)[1]
df <- round(summary(mod1)$fstatistic, 1)[2:3]
#write out the equation to be printed to plot
eq <- paste("F[",df[1],"]","[,]","[",df[2],"]==",Fstat)
#plot the data and label with the equation
qplot(x, y) + annotate("text", x=2, y=8, label=eq, parse=TRUE)
您可以将下标设为字符串值:
> eq <- paste("F['",df[1],",",df[2],"']==",Fstat,sep="")
> eq
[1] "F['1,8']==1579.927"
> qplot(x, y) + annotate("text", x=2, y=8, label=eq, parse=TRUE)
我想在使用 ggplot2 创建的图形上打印线性回归的 F 统计量和 df。我已经非常接近了,但我似乎无法在自由度(1 和 8)之间出现逗号。
#generate some data
x <- 1:10
y <- 1:10 + rnorm(10, 0.1, 0.2)
#run linear regression
mod1 <- lm(y~x)
#get r2 and df and round for better printing
Fstat <- round(summary(mod1)$fstatistic, 3)[1]
df <- round(summary(mod1)$fstatistic, 1)[2:3]
#write out the equation to be printed to plot
eq <- paste("F[",df[1],"]","[,]","[",df[2],"]==",Fstat)
#plot the data and label with the equation
qplot(x, y) + annotate("text", x=2, y=8, label=eq, parse=TRUE)
您可以将下标设为字符串值:
> eq <- paste("F['",df[1],",",df[2],"']==",Fstat,sep="")
> eq
[1] "F['1,8']==1579.927"
> qplot(x, y) + annotate("text", x=2, y=8, label=eq, parse=TRUE)