我使用stat_polyeq在图表上显示计算的线性方程,但显示的结果与实际结果有很大差异。实际斜率不能大于0.5。有人能帮助我纠正这个错误吗?
以下是我的数据:
df<-structure(list(Variety = c("Sultana - MG 000", "ES Pallador - MG I",
"Isidor - MG I", "Santana - MG I/II", "Blancas - MG II", "Ecudor - MG II"
), FTSWt2017 = c(0.54, 0.47, 0.41, 0.18, 0.25, 0.18), FTSWt2021 = c(0.32,
0.27, 0.35, 0.29, 0.22, 0.32)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -6L))
字符串
下面是我的代码:
library(ggplot2)
library(ggpmisc)
library(ggrepel)
library(stringr)
library(stats)
ggplot(df, aes(x = FTSWt2017, y = FTSWt2021)) +
geom_point(aes(color = Variety)) +
geom_smooth(method = "lm", formula = 'y ~ x', se=FALSE,color="black") +
geom_abline(intercept = 0, slope = 1, color="gray",
linetype="dashed", size=0.5)+
(
aes(label = paste(
gsub(
'\\.',
"*paste('.')*",
str_replace_all(after_stat(eq.label), "\\.([0-9])[0-9]", "\\.\\1")
),
gsub('\\.', ".", after_stat(rr.label)),
sep = "*plain(\";\")~~"
)))
型
下面是输出图:
enter image description here
1条答案
按热度按时间k5hmc34c1#
当你想将显示的系数四舍五入到2位数时,我认为最简单的方法是设置
output.type="numeric"
,这将给予你访问包含系数的tibble
,这使得更容易实现你想要的结果,而不是操作plotmath
字符串:字符串
的数据