ggplot2的stat_smooth出现错误

3

我尝试使用ggplot2时收到了一个错误,但我不明白为什么。 我可能在某个地方犯了一些小错误...

    > head(d)
      TargetGroup2012 TargetGroup2000     bmi3 age3 PA_Score education3 asthma3 allasthma3 tres3
    1               2               2 20.89796   55        2          2       0          0     0
    2               2               2 20.20038   49        3          2       0          0     0
    3               2               2 30.47797   58        3          1       0          0     0
    4               2               2 34.13111   51        2          2       0          0     0
    5               3               2 23.24380   52        3          1       0          0     0
    6               3               2 16.76574   62        2          3       0          0     0
      wheeze3 SmokingGroup_Kai groupchange
    1       0                4           4
    2       1                4           4
    3       0                5           4
    4       1                4           4
    5       0                3           5
    6       0                3           5
    > 

    ggplot() + 
      stat_smooth(data=d,aes(x=bmi3,y=asthma3),
                  method="gam",
                  formula=asthma3~bmi3, 
                  family="binomial")

# this is the ouput
# Error in eval(expr, envir, enclos) : object 'asthma3' not found


#this one works

    ggplot()+ stat_smooth(data=d,aes(x=bmi3,y=asthma3),
                  formula=asthma3~bmi3, 
                  family="binomial")

我的代码出了什么问题?


4
尝试在 stat_smooth 函数中将公式更改为 formula = y ~ x - David Arenburg
这个可以工作,但如果我想要一个有多个输入的公式怎么办? - Donbeo
我想了一下,如何在二维图上绘制多元回归?你应该通过某个变量进行facet_grid,并将每个变量分别绘制。或者最好的方法是绘制杠杆图。 - David Arenburg
是的,我想绘制仅BMI3,但我希望BMI3的估计考虑其他预测变量的值。就像y=s(x1)+s(x2),然后plot(x1,s(x1))这样。 - Donbeo
是的,我知道。但 ggplot 有更多有用的选项,比如“group”和“color”。如果我很快找不到答案,我将被迫使用 geom_line,但这意味着要做更多的工作 :-( - Donbeo
显示剩余2条评论
1个回答

4

将stat_smooth中的公式参数改为:

 formula = y ~ x

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接