将对数曲线绘制到散点图

时间:2014-01-24 13:20:24

标签: r plot curve-fitting

我面临一个可能非常容易解决的问题:在散点图中添加对数曲线。 我已经创建了相应的模型,现在只需要添加相应的曲线/线。

目前的模型如下:

### DATA
SpStats_urbanform <- c (0.3702534,0.457769,0.3069843,0.3468263,0.420108,0.2548158,0.347664,0.4318018,0.3745645,0.3724192,0.4685135,0.2505839,0.1830535,0.3409849,0.1883303,0.4789871,0.3979671)

co2 <- c (6.263937,7.729964,8.39634,8.12979,6.397212,64.755192,7.330138,7.729964,11.058834,7.463414,7.196863,93.377393,27.854284,9.081405,73.483949,12.850917,12.74407)

### Plot initial plot
plot (log10 (1) ~ log10 (1), col = "white", xlab = "PUSHc values", 
      ylab = "Corrected  GHG emissions [t/cap]", xlim =c(0,xaxes), 
      ylim =c(0,yaxes), axes =F)

axis(1, at=seq(0.05, xaxes, by=0.05),  cex.axis=1.1)
axis(2, at=seq(0, yaxes, by=1), cex.axis=1.1 )


### FIT
fit_co2_urbanform <- lm (log10(co2) ~ log10(SpStats_urbanform)) 


### Add data points (used points() instead of simple plot() bc. of other code parts)
points (co2_cap~SpStats_urbanform, axes = F, cex =1.3)

现在,我已经完成了所有的fit_parameters并且仍然无法为co2_cap(y轴)构建相应的拟合曲线~SpStats_urbanform(x轴)

任何人都可以帮我完成这一小段代码吗?

1 个答案:

答案 0 :(得分:-1)

首先,如果要在日志日志空间中绘图,则必须使用参数log="xy"指定它:

plot (co2~SpStats_urbanform, log="xy")

然后,如果要添加回归线,请使用abline

abline(fit_co2_urbanform)

enter image description here

编辑 :如果您不想以对数对数比例进行绘图,那么您必须翻译等式{{1}进入log10(y)=a*log10(x)+b并将其与y=10^(a*log10(x)+b)

一起绘制
curve

enter image description here

相关问题