stan-dev / bayesplot

bayesplot R package for plotting Bayesian models
https://mc-stan.org/bayesplot
GNU General Public License v3.0
433 stars 83 forks source link

Error: polygon edge not found when using bayesplot #283

Open njtierney opened 2 years ago

njtierney commented 2 years ago

Hi there!

Thanks for maintaining bayesplot!

I've got a bit of a funny issue that I was wondering if you have encountered with bayesplot. I find that sometimes, but not always, GitHub actions fails building a vignette when calling a function from bayesplot, giving the error:

Quitting from lines 469-474 (get_started.Rmd) 
  Error: processing vignette 'get_started.Rmd' failed with diagnostics:
  polygon edge not found
  --- failed re-building ‘get_started.Rmd’

(GH action line here: https://github.com/greta-dev/greta/runs/5233369273?check_suite_focus=true#step:11:245)

This is occurring at this line of the vignette:

https://github.com/greta-dev/greta/blob/master/vignettes/get_started.Rmd#L469-L473

Having a look around, it initially appeared that there was an issue with fonts: https://community.rstudio.com/t/ggplot2-polygon-edge-not-found/116475/4 - however, taking a look at your code it doesn't seem that there are custom fonts loaded, so I'm not sure why this is happening.

In any case, please do feel free to close this issue, I just thought in case you've come across this before, if you have any tips on how to resolve this!

Cheers!

JasonPekos commented 2 years ago

Just chiming in to say that I often encounter a similar bug when using bayesplot:

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

This bug will randomly pop up, forcing an R restart before I can use any bayesplot functions or themes. I can run the same code multiple times, and only sometimes — probability < 0.05 as a rough guess — will this break my R session.


Here's some more info:


I've tried many of the fixes for similar issues online — e.g. validating fontbook, etc. — and none of them fix the issue. It's really difficult to track down what could be going wrong because it's not a deterministic bug, so any suggestions are very appreciated.

JasonPekos commented 2 years ago

Ok, found this ... seems like for me, it's probably a really crazy concurrency bug with quartz.

I'm not sure why ggplot still works for me without the bayesplot theme, but I think there's probably(?) nothing going wrong on bayesplot's end here.


Update: reinstalling X11 seems to have fixed the problem.

Second update: nope, it still shows up, but more less often now.

jgabry commented 1 year ago

Sorry for the very slow reply! This got lost somewhere in my long list of issues to deal with.

Thank you both for reporting this. I also get this error occasionally and have been unable to figure out how to resolve it because I can't seem to deterministically reproduce it. Sometimes it happens during GitHub actions checks when building vignettes, like what @njtierney reported, other times it doesn't happen. I don't think I've ever had it happen in an interactive session.

This bug will randomly pop up, forcing an R restart before I can use any bayesplot functions or themes. I can run the same code multiple times, and only sometimes — probability < 0.05 as a rough guess — will this break my R session.

@JasonPekos Does it tend to be a particular bayesplot function where this initially happens?

JasonPekos commented 1 year ago

@jgabry I'm not sure if this will help you narrow it down, but I see the issue whenever I use the BayesPlot + theme_default(), even if I'm not calling a specific bayesplot function (e.g. mcmc_pairs() or whatever). So something like:

plot <-  ggplot() + theme_default()

And then adding some geoms with something like:

plot <- plot + geom_line(data = dat, 
                         aes(x = 1:nrow(dat), y = quant),
                         color = color_scheme_get()$light_highlight,
                         alpha = 0.1)

(I don't think the specifics are super important here, but this is an example of something that will break for me).

The error will show up here when I try to actually display the plot.


Note: Just so I don't send you down the wrong path, I am using mcmc_pairs() a lot in the same R session, so it could be that this is where the corruption ultimately stems from. Though I don't think so!

JasonPekos commented 1 year ago

Ok I actually have the problem currently in an interactive R session, here's a quick test: I can take the above code:

plot <-  ggplot() + theme_default()

plot <- plot  + geom_whatever()

And I get the error. I can go into my plotting functions and change the theme:

plot <-  ggplot() + theme_classic()

And remake the plots. When I do this, the error disappears1 and the plots display fine. So I think it's probably something do do with the BayesPlot theme.

1: Edit — disapears for only the new plots, bayesplot plots still won't display until I kill and restart my R session

JasonPekos commented 1 year ago

If this helps anyone narrow it down: I can test different output formats with:

ggsave(filename = "something.extension",
       plot = plotname)

The following don't work:

That is, they fail with:

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

The following don't work, but in a weird way:

The following probably work:

./test.tex:4599: TeX capacity exceeded, sorry [main memory size=5000000].
\!plot ...menA \raise \!dimenB \copy \!plotsymbol 
                                                  \kern -\!dimenA \ignorespa...
l.4599 ...om 393.89 326.17 center at 393.89 323.13

./test.tex:4599:  ==> Fatal error occurred, no output PDF file produced!

which I think just means the plot is too big for my TeX install? The actual output looks sane.

The following definitely work:

Not much to say here. Output is fine.

jgabry commented 1 year ago

Thanks @JasonPekos, that's really helpful! Much appreciated.

I'll try to make some time to dig into this further.

ischmidt20 commented 10 months ago

Seeing the same issue (M1 macbook as well). Any progress on this?