wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
651 stars 37 forks source link

Intermittent error with `theme(legend.text = element_markdown()` when combined with colour scale #33

Open ntthung opened 4 years ago

ntthung commented 4 years ago
DF <- data.frame(x = rnorm(100), 
                 y = rnorm(100),
                 z = rnorm(100),
                 type = c(rep('C', 50), rep('delta', 50)))

ggplot(DF) +
  geom_point(aes(x, y, colour = z, shape = type)) +
  scale_shape_discrete(labels = function(x) ifelse(x == 'C', 
                                                   '<sup>14</sup>C',
                                                   '&delta;<sup>18</sup>O')) +
  scale_colour_distiller(palette = 'RdBu', direction = 1) +
  facet_wrap(vars(type)) +
  theme(legend.text = ggtext::element_markdown())

Error in grid.Call.graphics(C_setviewport, vp, TRUE) : non-finite location and/or size for viewport

and the figure comes without legend text:

image

The strange thing is that if I keep rerunning the code time after time, sometimes the plot can be rendered without error.

image

Versions:

Jesse-Kerr commented 3 years ago

Also having the same issue

SAuderset commented 2 years ago

I have the same issue. It worked fine for a week and suddenly I get this error. Updated all my packages and installed the development version of ggtext, but nothing helps... The weirdest thing is that it only with some plots and not others, even though I use the exact same set up.