Computation failed in `stat_smooth()`: object not found

4,495 views
Skip to first unread message

Moritz Camenzind

unread,
Jun 19, 2018, 7:29:04 AM6/19/18
to ggplot2
Dear All,

I am trying to plot a logarithmic model to my data as follows:

ggplot(sub_tillers, aes(x = gdd, y = tillers))+
      geom_line()+
      geom_smooth(method = "lm", formula = tillers ~ log(ggd))

However, I get the following message (in German):

Computation failed in `stat_smooth()`:
Objekt 'tillers' nicht gefunden

The same code works perfectly, if I do not add the formula argument.

Added is my dataset and here my session info:

R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 17.10

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale:
 [1] LC_CTYPE=de_DE.UTF-8       LC_NUMERIC=C               LC_TIME=de_DE.UTF-8        LC_COLLATE=de_DE.UTF-8   
 [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=de_DE.UTF-8    LC_PAPER=de_DE.UTF-8       LC_NAME=C                
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C      

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] plyr_1.8.4     ggsnippets_1.0 digest_0.6.15  gridExtra_2.3  gtable_0.2.0   dplyr_0.7.4    tidyr_0.8.0    ggplot2_2.2.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.16     bindr_0.1.1      magrittr_1.5     munsell_0.4.3    colorspace_1.3-2 R6_2.2.2         rlang_0.2.0    
 [8] tools_3.4.4      yaml_2.1.18      lazyeval_0.2.1   assertthat_0.2.0 tibble_1.4.2     bindrcpp_0.2.2   purrr_0.2.4    
[15] glue_1.2.0       labeling_0.3     compiler_3.4.4   pillar_1.2.1     scales_0.5.0     pkgconfig_2.0.1


I hope this info is sufficient and thanks a lot in advance,

Moritz Camenzind


sub_tillers.csv

Roman Luštrik

unread,
Jun 19, 2018, 8:24:58 AM6/19/18
to moritz.c...@gmail.com, ggplot2
You need to refer to the variables as you map them in aes. `tillers` should become `y` and `gdd` `x`.

See?
> ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) +
+   geom_point() +
+   geom_smooth(method = "lm", formula = Petal.Length ~ Sepal.Length)
Warning message:
Computation failed in `stat_smooth()`:
object 'Petal.Length' not found

Whereas if variables from `aes` are used:

> ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) +
+   geom_point() +
+   geom_smooth(method = "lm", formula = y ~ log(x))
>

Cheers,
Roman

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
In God we trust, all others bring data.

Moritz Camenzind

unread,
Jun 19, 2018, 8:42:12 AM6/19/18
to ggplot2
Hi Roman

It works perfectly now.

Thanks a lot for your quick answer, it's much appreciated!

Have a nice day,
Moritz
Reply all
Reply to author
Forward
0 new messages