为什么科学记数法在R中的e后面多了一个字符“1”?

9jyewag0  于 2023-05-20  发布在  其他
关注(0)|答案(2)|浏览(155)

图上打印了一个额外的字符“1”。为什么会这样以及如何消除这种情况?
MWE:

data <- ChickWeight

par(mar = c(4,4,0.5,0.5) + 0.1, mgp = c(2.75,1,0), las = 1, cex = 1.2)

data.lm <- lm(weight ~ Time, data = data)

plot(weight ~ Time, data = data, col = "magenta", pch = 19, ylab = "Weight (gms)", xlab = "Time (days)", ylim = c(25, 375), xlim=c(0,22))

abline(data.lm, col="blue", lty = 2, lwd = 2)

a <- round(data.lm$coefficients[[1]], 2)
b <- round(data.lm$coefficients[[2]], 2)

# err <- format(mean(data.lm$residuals), scientific = TRUE, digits = 3) # its not working leaving a "1" at the end of the equation. No idea, why?

err <- round(mean(data.lm$residuals),17)
# equation of the line : 
eq <- paste("Weight =",a,"+",b,"\u00D7 Time",err,cex=1)

mtext(paste(eq),side=3,line=-1.1,padj=-0.25,adj=0.05,cex=0.8)

ifmq2ha2

ifmq2ha21#

您可以在mtext中使用cex一次,如下所示:

data <- ChickWeight

par(mar = c(4,4,0.5,0.5) + 0.1, mgp = c(2.75,1,0), las = 1, cex = 1.2)

data.lm <- lm(weight ~ Time, data = data)

plot(weight ~ Time, data = data, col = "magenta", pch = 19, ylab = "Weight (gms)", xlab = "Time (days)", ylim = c(25, 375), xlim=c(0,22))

abline(data.lm, col="blue", lty = 2, lwd = 2)

a <- round(data.lm$coefficients[[1]], 2)
b <- round(data.lm$coefficients[[2]], 2)

# err <- format(mean(data.lm$residuals), scientific = TRUE, digits = 3) # its not working leaving a "1" at the end of the equation. No idea, why?

err <- round(mean(data.lm$residuals),17)
# equation of the line : 
eq <- paste("Weight =",a,"+",b,"\u00D7 Time",err)

mtext(paste(eq),side=3,line=-1.1,padj=-0.25,adj=0.05,cex=1)

创建于2023-05-17带有reprex v2.0.2

2skhul33

2skhul332#

已解决:

# equation of the line : 
# Delete cex=1 here
# eq <- paste("Weight =",a,"+",b,"\u00D7 Time",err,cex=1)
eq <- paste("Weight =",a,"+",b,"\u00D7 Time",err)

相关问题