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

I know that the name of this question is a duplicate of this question and this question , but the solutions do not work there, and the error message is (slightly) different:

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

(note the missing part about the missing font)

I tried all the suggestions I found (updating / reinstalling all downloaded ggplot2, GGally graphic packages and scaling, reinitializing fonts on Mac OSX, starting in safe mode, moving fonts from / Fonts / (Disabled) back to / Fonts ... ), but none of them solved the problem.

An error occurs when I draw a ggplot graph with

scale_y_continuous(label=scientific_10)

where is scientific_10defined as

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

, scales - .

, , , ...

> 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]], ...)
+4
5

, 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)
+3

, , R , .

(. ), , , . , , R read.table() (: "HLA-DOA" "HLA.DOA" ).

ComplexHeatmap , :

oncoPrint(mat, 
      get_type = function(x) strsplit(x, ";")[[1]],
      alter_fun_list = alter_fun_list, 
      col = col, 
      row_order = my_order,
      column_title = "OncoPrint",
      heatmap_legend_param = list(title = "Alternations", at = c("AMP", "HOMDEL", "MUT"), labels = c("Amplification", "Deep deletion", "Mutation"))
)

:

  • mat - ,
  • my_order , , mat,
  • ,

R " ", - :

row_order <- gsub("\\.", "-", row_order)

, - , , .

0

aes,

:

p < - p + theme (text = element_text (family = "宋体" ))

, .

0

, MAC-, ... , 10- , ggplot trycatch , ...

:

error_appeared <- FALSE
  repeat{
    tryCatch({ # we put everything into a try catch block, because sometimes we get an error
      gscat <- 
        ggplot() # my ggplot command which sometimes fail

      ggsave('file.pdf', gscat, width=8,height=8)
      plot(gscat)
    },
    error=function(e) {
      print('redo the ratioscatterplot.')
      error_appeared <- TRUE
    }
    )
    if(!error_appeared){
      break
    }
  }

, , / ! .

, -, , !

:
- " ", 2 20 .

library(scales)
library(ggplot2)
df <- data.frame(
    log2.Ratio.H.L.normalized.rev = c(2.53861265542646, 0.402176424979483, 0.438931541934545, 0.639695233399582, 0.230203013366421, 
                                      2.88223218956399, 1.23051046036618, 2.56554843533357, 0.265436896049098, 
                                      1.32866415755805, -0.92108963514092, 0.0976107966264223, -0.43048946484291, 
                                      -0.558665259531966, 4.13183638727079, 0.904580434921318, -0.0733780789564803, 
                                      -0.621932351219966, 1.48594198341242, -0.365611185917855, 1.21088754922081, 
                                      -2.3717583289898, 2.95160644380282, 3.71446534016249), 
    Intensity = c(5951600000, 2.4433e+10, 1.1659e+10, 2273600000, 6.852e+10, 9.8746e+10, 5701600000, 
                  1758500000, 987180000, 3.4167e+11, 1.5718e+10, 6.8888e+10, 5.5936e+10, 
                  8702900000, 1093500000, 4426200000, 1.3681e+11, 7.773e+09, 5860400000, 
                  1.2861e+12, 2017900000, 2061300000, 240520000, 1382700000), 
    my_label = c("RPL18", 
                 "hCG_2024613", "NOL7", "PRPF4B", "HIST1H2BC", "XRCC1", "C9orf30", 
                 "CABIN1", "MGC3731", "XRCC6", "RPL23", "RPL27", "RPL17", "RPL32", 
                 "XPC", "RPL15", "GNL3", "RPL29", "JOSD3", "PARP1", "DNAPTP6", 
                 "ORC2L", "NCL", "TARDBP"))

unlink("figures", recursive=TRUE)
if(!dir.exists('figures')) dir.create('figures')
for(i in 1:20) {
  error_appeared <- FALSE
  repeat{
    tryCatch({ # we put everything into a try catch block, because sometimes we get an error
      gscat <-
        ggplot(df, aes_string("log2.Ratio.H.L.normalized.rev", 'Intensity')) +
        geom_point(data=df[abs(df[["log2.Ratio.H.L.normalized.rev"]]) < 1,],
                   color='black', alpha=.3, na.rm=TRUE) +
        scale_y_log10(labels = scales::trans_format("log10", scales::math_format()))

      ggsave(file.path('figures', paste0('intensity_scatter_', i, '.pdf')),
             gscat, width=8, height=8)
      plot(gscat)
    },
    error=function(e) {
      # print(e)
      print(sprintf('%s redo the ratioscatterplot.', i))
      error_appeared <- TRUE
    }
    )
    if(!error_appeared){
      break
    }
  }
}
0

I had the same problem when trying to build ggplot / grid output in a graph window in Rstudio. However, plotting on an external graphics device seems to work fine.

The external device depends on your system, but the script below, paraphrased from this blog , works for most systems:

a = switch(tolower(Sys.info()["sysname"]),
               "darwin"  = "quartz",
               "linux"   = "x11",
               "windows" = "windows")
options("device" = a)
graphics.off()
rm(a)

and return to using the Rstudio chart window:

options("device"="RStudioGD")
graphics.off()

Please note that when you switch, you lose any existing graphics.

-1
source

Source: https://habr.com/ru/post/1619470/


All Articles