ggplot2中考虑不同因素的调整回归线
Adjusted regression line considering different factors in ggplot2
我正在尝试重现下图,其中内部线是调整后的回归线:
但是,由于某些因素,它没有按应有的方式绘制,也就是说,只显示了一条线,而且,变量“teor”的不同浓度没有像在上图,见下图:
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,color="black"),
text = element_text(size = 50,color="black"),
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,color="black"),
text = element_text(size = 50,color="black"),
legend.position = "none") + facet_wrap(~Fator)
输出:
作为研究人员,您应该定义什么。
我正在尝试重现下图,其中内部线是调整后的回归线:
但是,由于某些因素,它没有按应有的方式绘制,也就是说,只显示了一条线,而且,变量“teor”的不同浓度没有像在上图,见下图:
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,color="black"),
text = element_text(size = 50,color="black"),
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,color="black"),
text = element_text(size = 50,color="black"),
legend.position = "none") + facet_wrap(~Fator)
输出:
作为研究人员,您应该定义什么。