r - ggplot2 stat_smooth 错误

标签 r ggplot2 gam

当我尝试使用 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")

我的代码有什么问题?

最佳答案

将 stat_smooth 中的公式参数更改为:

 formula = y ~ x

关于r - ggplot2 stat_smooth 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23591887/

相关文章:

r - 是否有与 plyr::join_all 等效的 dplyr 或 data.table?通过数据框列表加入?

r - 在一页上绘制 4 个图,并使用 R 中的常见图例

python - 如何在 matplotlib 中创建密度图?

r - 两种处理之间的ggplot背景突出显示

r - 防止 plot.gam 生成图形

r - 从正弦噪声预测值

r - 如何在 R 中使用带有 gam 的样条曲线拟合所有变量而不键入每个变量?

r - 如何将 data.table::fread 包装在你自己的包中,具有 bit64 功能?

r - 如何在不使用 %>% 的情况下以常规范式编写以下代码?

r - ggimage:来自计算机而非网络的自定义图像