微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

调整回归线考虑 ggplot2 中的不同因素

如何解决调整回归线考虑 ggplot2 中的不同因素

我正在尝试重现下图,其中内部线是调整后的回归线:

然而,由于某些因素,它没有被绘制成它应该是的样子,也就是说,出现了一条线,而且,变量“teor”的不同浓度没有像图像中那样被绘制上面,看下面的结果:

数据:https://drive.google.com/file/d/1Y-GsNNcYINqtO-hcJfNRgaj545JZXZIS/view?usp=sharing

dados = read.table("datanew.csv",header = T,sep=";",dec=","); head(dados)
dados$Trat <- factor(dados$Trat)
dados$Teor <- factor(dados$Teor)
dadosnew$Tempo = as.factor(dadosnew$Tempo)

my.formula <- y ~ x
p = ggplot(dadosnew,aes(x = Tempo,y = massaseca,group = Fator)) +
  stat_summary(geom = "point",fun = mean) + 
  stat_smooth(method = "lm",se=FALSE,formula=y ~ poly(x,2,raw=TRUE)) + stat_poly_eq(formula = my.formula,eq.with.lhs = "As-italic(hat(y))~`=`~",aes(label = paste(..eq.label..,..rr.label..,sep = "*plain(\",\")~")),parse = TRUE,size = 5,label.y = 35)+
  labs(title = "",x = "Time (Minutes)",y = "Weight (mg)") + theme_bw() +
  theme(axis.title = element_text(size = 23,color="black"),axis.text = element_text(size = 18,text = element_text(size = 50,legend.position = "none") + facet_wrap(~Fator)
p 

解决方法

您需要另一个这样的分组变量:

#Code
my.formula <- y ~ x
ggplot(dadosnew,aes(x = Tempo,y = massaseca,group = interaction(Fator,Trat))) +
  stat_summary(geom = "point",fun = mean) + 
  stat_smooth(method = "lm",se=FALSE,formula=y ~ poly(x,2,raw=TRUE)) +
  stat_poly_eq(formula = my.formula,eq.with.lhs = "As-italic(hat(y))~`=`~",aes(label = paste(..eq.label..,..rr.label..,sep = "*plain(\",\")~")),parse = TRUE,size = 5,label.y = 35)+
  labs(title = "",x = "Time (Minutes)",y = "Weight (mg)") + theme_bw() +
  theme(axis.title = element_text(size = 23,color="black"),axis.text = element_text(size = 18,text = element_text(size = 50,legend.position = "none") + facet_wrap(~Fator)

输出:

enter image description here

作为研究人员,您应该定义哪些内容。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。