r - grid.Call(L_textBounds,as.graphicsAnnot(x $ label),x $ x,x $ y,: polygon edge not found (new)中的错误

标签 r ggplot2

我知道这个问题的标题是this Questionthis Question的副本,但是那边的解决方案对我不起作用,并且错误消息(略有不同):

Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
polygon edge not found

(请注意有关丢失字体的缺失部分)

我尝试了所有发现的建议(更新/重新安装所有已加载的图形包,ggplot2,GGally和缩放比例,通过以安全模式启动将Mac OSX上的字体重新初始化,将字体从/Fonts/(禁用)移回/Fonts。 ..),但没有一个解决问题。

当我用以下方法绘制ggplot图时,似乎发生了错误
scale_y_continuous(label=scientific_10)

其中scientific_10定义为
scientific_10 <- function(x) {
parse(text = gsub("e", " %*% 10^", scientific_format()(x)))
}

因此,我怀疑scales库与它有关。

最令人困惑的是,错误仅在某次或多次出现,可能是我尝试绘制同一张图的第3或5次。
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.9.5 (Mavericks)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] gridExtra_2.0.0 scales_0.3.0    broom_0.4.0     tidyr_0.3.1             ggplot2_1.0.1   GGally_0.5.0    dplyr_0.4.3    

loaded via a namespace (and not attached):
 [1] Rcpp_0.11.5      magrittr_1.5     MASS_7.3-43      mnormt_1.5-1         munsell_0.4.2    colorspace_1.2-6 lattice_0.20-33  R6_2.0.1        
 [9] stringr_0.6.2    plyr_1.8.1       tools_3.2.2      parallel_3.2.2       grid_3.2.2       gtable_0.1.2     nlme_3.1-121     psych_1.5.8     
[17] DBI_0.3.1        htmltools_0.2.6  lazyeval_0.1.10  yaml_2.1.13      assertthat_0.1   digest_0.6.8     reshape2_1.4.1   rmarkdown_0.8.1 
[25] labeling_0.3     reshape_0.8.5    proto_0.3-10    

traceback()
35: grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, 
    resolveHJust(x$just, x$hjust), resolveVJust(x$just, x$vjust), 
    x$rot, 0)
34: widthDetails.text(x)
33: widthDetails(x)
32: (function (x) 
{
    widthDetails(x)
})(list(label = expression(5 %*% 10^+5, 7.5 %*% 10^+5, 1 %*% 
    10^+6, 1.25 %*% 10^+6, 1.5 %*% 10^+6), x = 1, y =   c(0.0777214770341215, 
0.291044141334423, 0.504366805634725, 0.717689469935027, 0.931012134235329
), just = "centre", hjust = 1, vjust = 0.5, rot = 0, check.overlap = FALSE, 
    name = "axis.text.y.text.8056", gp = list(fontsize = 9.6, 
        col = "black", fontfamily = "", lineheight = 0.9, font = 1L), 
    vp = NULL))
31: grid.Call.graphics(L_setviewport, vp, TRUE)
30: push.vp.viewport(X[[i]], ...)

最佳答案

我通过安装库extrafont,安装一组特定字体并强制ggplot仅使用以下字体来解决该问题:

    require(extrafont)
    # need only do this once!
    font_import(pattern="[A/a]rial", prompt=FALSE)
    require(ggplot2)
    # extending the help file example
    df <- data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30))
    ds <- plyr::ddply(df, "gp", plyr::summarise, mean = mean(y), sd = sd(y))
    plotobj <- ggplot(df, aes(gp, y)) +
      geom_point() +
      geom_point(data = ds, aes(y = mean), colour = 'red', size = 3) + 
      theme(text=element_text(size=16, family="Arial"))
    print(plotobj)

关于r - grid.Call(L_textBounds,as.graphicsAnnot(x $ label),x $ x,x $ y,: polygon edge not found (new)中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34220883/

相关文章:

r - 在函数内找不到 lapply data.table 的对象

r - 如何更改 ggplot 中小平面上 strip 的大小?

r - 具有刻面比例和动态 geom_text 位置的 ggplot

r - 如何在 geom_tile ggplot 中移动图 block 右/左端的刻度线和标签?

r - 包装 R 的绘图函数(或 ggplot2)以防止绘制大数据集

mysql - 使用来自服务器的 MySQL 数据更新 Shiny R 中的 selectInput

r - 通过字符串定义曲线()

r - 如何替换从左下角到右上角的对角线下方矩阵中的值?

r - 如何使用 y 作为 ggplot2 中每个 bin 的 x 值的总和绘制直方图

r - 从 SQLite blob 中提取的错误打印图