如何在双对数图中绘制两个线性回归(在r中)?

时间:2017-05-23 07:34:01

标签: r

我正在努力研究如何在r中创建双对数图,以及如何在此图中绘制两个线性回归。我已成功将x轴转换为对数轴,但我无法将y轴转换为对数轴。

我使用的代码就是这个,它在下面的链接中创建了图:

PR_abs <- lm(PR.Interval..s. ~ log.BM., data = rest)
PR_abs.d <- lm(PR.Interval..s. ~ log.BM., data = dist[4:21,])
   plot(rest$Body.Mass..kg.,rest$PR.Interval..s., xlab = "", type="n", 
    ylab= "PR duration (sec)", pch=20, ylim= c(0,1), log="x", cex=1.4)
points(rest[1:3,]$Body.Mass..kg., rest[1:3,]$PR.Interval..s., cex=1.2,pch=17)
points(rest[4:21,]$Body.Mass..kg., rest[4:21,]$PR.Interval..s., cex=1.2, pch=16)
points(rest[4:21,]$Body.Mass..kg., dist[4:21,]$PR.Interval..s., cex=1.2, pch=1)
lines(rest$Body.Mass..kg.,PR_abs$fitted.values)
lines(rest[4:21,]$Body.Mass..kg.,PR_abs.d$fitted.values,lty=2)
legend("topleft", c("Rest","Exercised","Embryo"), cex=0.8, bty="n", lty=c(1,2,0),
   pch=c(16,1,17))

enter image description here

我也尝试过使用ggplot2,但没有成功:

ggplot(data = rest, aes(x = Body.Mass..kg., y = QT..RR)) +
  geom_point(data = rest, aes(x = Body.Mass..kg., y = QT..RR), shape=1)+
  geom_abline(aes(intercept=coef(QT_rel)[1],slope=coef(QT_rel)[2])) +
  coord_trans(y="log2", x="log2")

有什么建议吗? :) 最好的,Ditte

0 个答案:

没有答案