wilkelab / cowplot

cowplot: Streamlined Plot Theme and Plot Annotations for ggplot2
https://wilkelab.org/cowplot/
701 stars 84 forks source link

Conversion failure warnings on unicode character #174

Closed bersbersbers closed 3 years ago

bersbersbers commented 3 years ago

Brief description of the problem or desired feature.

library(ggplot2)
df <- data.frame(x = 1, y = 1, color = "−") # this is a unicode minus sign (U+2212)
p <- ggplot(df, aes(x = x, y = y, color = color)) +
    geom_point()
cp <- cowplot::plot_grid(p)

On my Linux system, this issues 30 warnings - basically, 10 times this:

1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  conversion failure on '−' in 'mbcsToSbcs': dot substituted for <e2>
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  conversion failure on '−' in 'mbcsToSbcs': dot substituted for <88>
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  conversion failure on '−' in 'mbcsToSbcs': dot substituted for <92>

I get the same warnings when I issue

grDevices::pdf("Bug.pdf")
p
dev.off()

but not when I issue

grDevices::cairo_pdf("Bug.pdf")
p
dev.off()

I don't know what plot_grid may be using the pdf device for, but is there a way to switch to cairo?

Related: https://github.com/rstudio/rstudio/issues/3680 and many more

bersbersbers commented 3 years ago

I should add that the output looks alright - could it be that the warnings are generated only during some measurement pass? If so, this still has potential to change the output in the general case, although not in mine - in which case I would ignore these warnings.

clauswilke commented 3 years ago

Does this help: set_null_device("cairo")?

https://wilkelab.org/cowplot/reference/set_null_device.html

bersbersbers commented 3 years ago

It does indeed! Sorry for missing that in the documentation, and thanks a lot for your help!