简体   繁体   English

R用置信区间绘制多个locfit模型

[英]R plotting multiple locfit models with confidence intervals

I'm attempting to plot two locfit models within one plot however I am unable to get the second locfit model to plot the confidence intervals. 我试图在一个图中绘制两个locfit模型,但是无法获得第二个locfit模型来绘制置信区间。 I've created two locfit models: 我创建了两个locfit模型:

1_fit = locfit(Y~Time,data=data_1)
2_fit = locfit(Y~Time,data=data_2)

Each can be plotted on their own just fine with the confidence intervals using the following: 每个人都可以使用下面的方法使用置信区间独立绘制它们:

plot(1_fit,band="local",type = "l", xlab = "Time", ylab = "Y-Axis",ylim=c(0,22), 
  col = "red",lwd = 5,font=3,main="Local Poly Fit 1",cex.lab=1.5, cex.axis=1.5, 
  cex.main=1.5, cex.sub=1.5)

However, when I attempt to plot an additional locfit model to the plot using: 但是,当我尝试使用以下方法在图上绘制其他locfit模型时:

lines(2_fit,col="blue")

I can only add the locfit line but not the confidence intervals. 我只能添加locfit线,而不能添加置信区间。 I've attempted to do: 我试图做:

lines(2_fit,band="local",col="blue")

But I get this message and no confidence intervals: 但是我收到此消息,并且没有置信区间:

Warning message: In plot.xy(xy.coords(x, y), type = type, ...) : "band" is not a graphical parameter

I've also looked into using lines.locfit , but had no luck as R just says that it can't find the function lines.locfit. 我也研究过使用lines.locfit ,但是运气不好,因为R只是说它找不到功能lines.locfit。

I have a work around to put both plots within the same window using: 我有一种解决方法,可以使用以下方法将两个图放在同一窗口中:

par(mfrow=c(2,1))

But would like to avoid this as it would make the plots more comparable if they were within the same plot. 但是要避免这种情况,因为如果它们在同一图中,则会使这些图更具可比性。

Answer was provided by Richard Telford in comments. 理查德·特尔福德(Richard Telford)在评论中提供了答案。 The following code was able to accomplish what I needed: 以下代码能够完成我所需要的:

    plot(1_fit,band="local",type = "l", xlab = "Time", ylab = "Y-Axis",ylim=c(0,22), xlim=c(0,12), col = "red",lwd = 5,font=3,main="Local Poly Fit 1",cex.lab=1.5, cex.axis=1.5, cex.main=1.5, cex.sub=1.5)`

    par(new = TRUE)

    plot(2_fit,band="local",type = "l", xlab = "Time", ylab = "Y-Axis",ylim=c(0,22), xlim=c(0,12),col = "blue",lwd = 5,font=3,main="Local Poly Fit 1",cex.lab=1.5, cex.axis=1.5, cex.main=1.5, cex.sub=1.5)` 

I needed to be sure that ylim and xlim were equal as well as main, ylab, and xlab. 我需要确保ylimxlim以及main,ylab和xlab相等。 Also a side note from Richard, 1_fit is not a legal name, I used it here just as a placeholder name but seems good knowledge to pass on. 也是理查德(Richard)的附带说明,1_fit不是法定名称,我在这里使用它只是作为占位符名称,但似乎可以继续使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM