Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何将非线性模型添加到散点图?_R_Ggplot2_Plot_Profile - Fatal编程技术网

R 如何将非线性模型添加到散点图?

R 如何将非线性模型添加到散点图?,r,ggplot2,plot,profile,R,Ggplot2,Plot,Profile,我想在散点图中添加一个带置信带的非线性模型。为了解释,我使用了0到1000米范围内的温度、盐度等垂直深度剖面数据。在交换轴之后,我不幸地未能添加带有置信带的回归模型。如果你们中有人能帮我开始这项工作,我将不胜感激 我的数据如下所示: CTD Area Station Cast Lat Long Month Day Hour Temp Sal DO Fluo Depth 898 9102 1 12 1 -44.59 174.2 10 24

我想在散点图中添加一个带置信带的非线性模型。为了解释,我使用了0到1000米范围内的温度、盐度等垂直深度剖面数据。在交换轴之后,我不幸地未能添加带有置信带的回归模型。如果你们中有人能帮我开始这项工作,我将不胜感激

我的数据如下所示:

     CTD Area Station Cast    Lat  Long Month Day Hour Temp  Sal    DO Fluo Depth
898 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.9  1.7   1.0
899 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.4  1.5   2.0
900 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.7  1.5   3.0
901 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.5  1.6   4.0
902 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.3  1.8   5.0
903 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.4  1.9   6.0
904 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.8  1.8   7.0
905 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.7  1.7   7.9
906 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.2  1.7   8.9
907 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.2  2.1   9.9
908 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.1  1.9  10.9
909 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.2  1.7  11.9
910 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.4  2.3  12.9
911 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.8  1.7  13.9
912 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.9  1.4  14.9
913 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 283.0  1.5  15.9
914 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.9  1.4  16.9
915 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.4  1.6  17.9
916 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 281.5  1.6  18.9
917 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 280.9  1.5  19.9
918 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 281.9  1.9  20.9
919 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 284.8  1.4  21.9
920 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 286.4  1.5  22.8
921 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 286.5  1.8  23.8
922 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 285.7  1.8  24.8
p1<-ggplot(A1,aes(x=Temp,y=Depth,group=Cast))+
  geom_point()+xlim(c(6,12))+scale_y_reverse(lim=c(500,0))
p1
在给定的示例中,最上面25米处的温度没有变化,但请相信我,下面的温度会变化

到目前为止,我的代码如下所示:

     CTD Area Station Cast    Lat  Long Month Day Hour Temp  Sal    DO Fluo Depth
898 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.9  1.7   1.0
899 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.4  1.5   2.0
900 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.7  1.5   3.0
901 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.5  1.6   4.0
902 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.3  1.8   5.0
903 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.4  1.9   6.0
904 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.8  1.8   7.0
905 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.7  1.7   7.9
906 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.2  1.7   8.9
907 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.2  2.1   9.9
908 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.1  1.9  10.9
909 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.2  1.7  11.9
910 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.4  2.3  12.9
911 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.8  1.7  13.9
912 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.9  1.4  14.9
913 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 283.0  1.5  15.9
914 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.9  1.4  16.9
915 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 282.4  1.6  17.9
916 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 281.5  1.6  18.9
917 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 280.9  1.5  19.9
918 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 281.9  1.9  20.9
919 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 284.8  1.4  21.9
920 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 286.4  1.5  22.8
921 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 286.5  1.8  23.8
922 9102    1      12    1 -44.59 174.2    10  24   20 10.7 34.6 285.7  1.8  24.8
p1<-ggplot(A1,aes(x=Temp,y=Depth,group=Cast))+
  geom_point()+xlim(c(6,12))+scale_y_reverse(lim=c(500,0))
p1

p1
ggplot
提供了使用
geom_平滑
自动拟合黄土曲线的可能性:

ggplot(A1,aes(x=Temp,y=Depth,group=Cast)) +
  geom_point() +
  geom_smooth() +
  xlim(c(6,12)) + 
  scale_y_reverse(lim=c(500,0))

然而,这是一个问题,如果你没有想要展示的实际模型,这是否符合你的需要。

你的模型是什么?大多数模型都会给出预测和置信区间,你可以将它们添加到你的情节中;不知道如何想出一个最好的。数据看起来像一个多项式形状,不是线性的或指数的。如果你没有模型,你可以在你感兴趣的
y
x
变量上拟合一个非参数函数(我认为分别是温度和深度)。为此,您可以使用
stats
包中的
lowss
smooth.spline
函数或
mgcv
函数中的
gam
函数。后者的文档内容为:“对于使用拟合模型预测的任何数量,都可以随时获得置信/可信区间。”以下问题的答案也可能很方便:谢谢,非常感谢您的建议!