2016-09-21 213 views
2

我最近將我的R版本升級到3.2.3,並更新了我的軟件包。然後我安裝了Github版本的ggplot2和CRAN版本ggrepel在使用github版ggplot2運行ggrepel時在zero_range()中出錯

的版本中使用的包:

ggplot2: 2.1.0.9000 
ggrepel: 0.5 
scales: 0.4.0 

但加載這些包後,我甚至不能運行提供ggrepel示例腳本:

library(ggrepel) 
p <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) 
# Avoid overlaps by repelling text labels 
p + geom_text_repel() 

Error in zero_range(from) : x must be length 1 or 2 

功能zero_range()距離scales包。然而,奇怪的是,如果我從CRAN (version 2.1.0)安裝ggplot2ggrepel開始按預期工作。
更新或重新安裝scalesggrepel沒有任何影響。

我記得在我舊版本的R 3.1.3中,我從Github安裝了ggplot2(使用字幕和標題),並且它在那裏工作得很好。

我的會話信息是:

R version 3.2.3 (2015-12-10) 
Platform: x86_64-w64-mingw32/x64 (64-bit) 
Running under: Windows 7 x64 (build 7601) Service Pack 1 

locale: 
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 
[4] LC_NUMERIC=C       LC_TIME=English_United States.1252  

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

other attached packages: 
[1] ggrepel_0.5  ggplot2_2.1.0.9000 

loaded via a namespace (and not attached): 
[1] labeling_0.3  colorspace_1.2-6 scales_0.4.0  assertthat_0.1 lazyeval_0.2.0 plyr_1.8.4  
[7] tools_3.2.3  gtable_0.2.0  tibble_1.2  Rcpp_0.12.7  grid_3.2.3  munsell_0.4.3 

從我調試,在此功能出現錯誤:

ggproto("LayerInstance", Layer, geom = geom, geom_params = geom_params, 
     stat = stat, stat_params = stat_params, data = data, 
     mapping = mapping, aes_params = aes_params, subset = subset, 
     position = position, inherit.aes = inherit.aes, show.legend = show.legend) 

而且其內部的:

function (`_class` = NULL, `_inherit` = NULL, ...) 
{ 
    e <- new.env(parent = emptyenv()) 
    members <- list(...) 
    if (length(members) != sum(nzchar(names(members)))) { 
     stop("All members of a ggproto object must be named.") 
    } 
    if (length(members) > 0) { 
     list2env(members, envir = e) 
    } 
    if (!is.null(`_inherit`)) { 
     if (!is.ggproto(`_inherit`)) { 
      stop("`_inherit` must be a ggproto object.") 
     } 
     e$super <- `_inherit` 
     class(e) <- c(`_class`, class(`_inherit`)) ###### Here layeth the error, as I think 
    } 
    else { 
     class(e) <- c(`_class`, "ggproto") 
    } 
    e 
} 

但我無能至於解決方案。

+3

我可以證實你的錯誤,你應該使用'ggplot2'的'CRAN'版本,並在這裏報告的錯誤:https://開頭github上。 com/hadley/ggplot2 /問題 –

+0

@J_F感謝您的確認! –

回答

4

使用最新的dev版本ggrepel,錯誤消失。

安裝與devtools::install_github("slowkow/[email protected]")

包版本:

ggplot2 * 2.1.0.9001 2016-10-07 Github (hadley/[email protected]) 
ggrepel * 0.6.2  2016-10-07 Github (slowkow/[email protected]) 
scales  0.4.0.9003 2016-10-07 Github (hadley/[email protected]) 
+3

實際上,解決方法是在每次安裝新ggplot2後重新安裝ggrepel。由於ggproto。通過slowkow和aphalo查看詳情https://github.com/slowkow/ggrepel/issues/55#issuecomment-255364286 – aurelien