r-lib / svglite

A lightweight svg graphics device for R
https://svglite.r-lib.org
180 stars 39 forks source link

$ sign rotated 90 degrees in at least one showtext / google font combination dodgy #36

Closed ellisp closed 9 years ago

ellisp commented 9 years ago

You may not even be aiming to work fully with {showtext} and it might be showtext's problem rather than yours, but for the record while this device works mostly ok with google fonts imported by showtext, in at least one situation ($ rotated 90 degrees) it doesn't work as well as grDevices::svg

Here's the devSVG version - notice the dollar sign on the y axis is a (little but noticeable) bit corrupt:

image

Here's the svg version, which works fine:

image

library(RSvgDevice)
library(ggplot2)
library(showtext)
font.add.google("Poppins", "myfont")
showtext.auto()
theme_set(theme_light(base_family = "myfont"))

devSVG("test_devSVG.svg")
ggplot(mtcars, aes(x = disp, y = mpg)) +
   geom_point() +
   theme_grey(base_family = "myfont") +
   labs(y = "$ doesn't work properly")
dev.off()

svg("test_svg.svg")
ggplot(mtcars, aes(x = disp, y = mpg)) +
   geom_point() +
   theme_grey(base_family = "myfont") +
   labs(y = "$ doesn't work properly")
dev.off()
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_New Zealand.1252  LC_CTYPE=English_New Zealand.1252    LC_MONETARY=English_New Zealand.1252
[4] LC_NUMERIC=C                         LC_TIME=English_New Zealand.1252    

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

other attached packages:
[1] showtext_0.4-2        sysfonts_0.5          ggplot2_1.0.1         gdtools_0.0.2         RSvgDevice_0.6.4.9000

loaded via a namespace (and not attached):
 [1] bitops_1.0-6      colorspace_1.2-6  digest_0.6.8      grid_3.1.2        gtable_0.1.2      jsonlite_0.9.16   labeling_0.3     
 [8] magrittr_1.5      MASS_7.3-44       munsell_0.4.2     plyr_1.8.3        proto_0.3-10      Rcpp_0.12.1       RCurl_1.95-4.7   
[15] reshape2_1.4.1    rstudio_0.98.1028 rstudioapi_0.3.1  scales_0.3.0      showtextdb_1.0    stringi_0.5-5     stringr_1.0.0    
[22] tools_3.1.2     

(the old version of R is deliberate to mimic my work setup, where upgrades of R are non-trivial so less frequent)

hadley commented 9 years ago

@yixuan any thoughts on what might cause this?

yixuan commented 9 years ago

As far as I know this is because RSvgDevice has not yet implemented the path() device function. showtext by default calls the path() device function to draw characters, and if it is not implemented, polygon() will be used instead as a fallback. However, the color filling strategy in polygon() is not as nice as path(), so the dollar sign has weird colors inside.

I could prepare a PR later to add the path() function to RSvgDevice if needed. :-)

yixuan commented 9 years ago

The PR https://github.com/mdecorde/RSvgDevice/pull/37 can solve this issue.

Below are the plots created by the new version:

ellisp commented 9 years ago

Works great, thanks.