英文:
why scientific notation leaves an extra character "1" after e in R?
问题
以下是您要翻译的代码部分:
An extra character of "1" is printing on the figure. Why so and how to remove this?
MWE:
```R
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,"× Time",err,cex=1)
mtext(paste(eq),side=3,line=-1.1,padj=-0.25,adj=0.05,cex=0.8)
英文:
An extra character of "1" is printing on the figure. Why so and how to remove this?
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)
答案1
得分: 1
你可以在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 (克)", xlab = "时间 (天)", 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) # 它不能正常工作,在方程末尾留下一个"1"。不知道为什么?
err <- round(mean(data.lm$residuals),17)
# 线的方程:
eq <- paste("Weight =",a,"+",b,"\u00D7 Time",err)
mtext(paste(eq),side=3,line=-1.1,padj=-0.25,adj=0.05,cex=1)
<!-- -->
<sup>2023-05-17创建,使用reprex v2.0.2</sup>
英文:
You could use the cex
once in your mtext
like this:
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)
<!-- -->
<sup>Created on 2023-05-17 with reprex v2.0.2</sup>
答案2
得分: 0
已解决:
# 线性方程式:
# 在此处删除 cex=1
# eq <- paste("Weight =",a,"+",b,"\u00D7 Time",err,cex=1)
eq <- paste("Weight =",a,"+",b,"\u00D7 Time",err)
英文:
Solved:
# 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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论