Search code examples
rfunctionnamespacespackageggfortify

ggfortify::autoplot or ggfortify:::autoplot not working


The following code works fine:

library(ggfortify)
autoplot(lm(Petal.Width ~ Petal.Length, data = iris), label.size = 3)

However ggfortify::autoplot and ggfortify:::autoplot do not work as expected. See below the codes with errors:

ggfortify::autoplot(lm(Petal.Width ~ Petal.Length, data = iris), label.size = 3)

Error: 'autoplot' is not an exported object from 'namespace:ggfortify'

ggfortify:::autoplot(lm(Petal.Width ~ Petal.Length, data = iris), label.size = 3)

Error in get(name, envir = asNamespace(pkg), inherits = FALSE) :
object 'autoplot' not found

Wonder what I am missing here. Thanks in advance for any help.

sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: i686-pc-linux-gnu (32-bit)
Running under: Ubuntu 16.04.1 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] ggfortify_0.3.0.9000 ggplot2_2.2.0       

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.8      tidyr_0.6.0      dplyr_0.5.0      assertthat_0.1   grid_3.3.2      
 [6] plyr_1.8.4       R6_2.2.0         gtable_0.2.0     DBI_0.5-1        magrittr_1.5    
[11] scales_0.4.1     lazyeval_0.2.0   labeling_0.3     tools_3.3.2      munsell_0.4.3   
[16] colorspace_1.3-1 gridExtra_2.2.1  tibble_1.2   

Solution

  • As @hrbrmstr indicates in his comment the correct way to call autoplot is:

    library(ggfortify)
    ggplot2::autoplot(lm(Petal.Width ~ Petal.Length, data = iris), label.size = 3)
    

    autoplot() is a function of ggplot that calls UseMethod("autoplot").