wch / extrafont

Tools for using fonts in R graphics
312 stars 49 forks source link

negative signs cause warning and errors in plot #54

Open ShanEllis opened 6 years ago

ShanEllis commented 6 years ago

I love extrafont, so thank you! But, I have run into something I can't seem to figure out. Minimal example of issue below. Negative values in scatterplot cause issues with plot output -- the negative signs overlap the values in the resulting plot.

This works just fine:

library(ggplot2)
library(extrafont)

fonts()

V1 <- sample(1:1000,512)
V2 <- sample(1:1000,512)
df2 = as.data.frame(cbind(V1,V2))
p <- ggplot(df2, aes(V1, V2)) + 
    geom_point()+
    theme(text = element_text(family="Roboto Condensed"))
ggsave("test.pdf", plot=p,  width=4, height=4)
embed_fonts("test.pdf",outfile="test.pdf")

But, when I add negative values to the data frame (only differences in code below are in assignments of values to V1 and V2), I get a warning and the negative signs overlap with the values on the axes in the resultant plot.

V1 <- sample(c(-1000:1000),512)
V2 <- sample(c(-1000:1000),512)
df2 = as.data.frame(cbind(V1,V2))
p <- ggplot(df2, aes(V1, V2)) + 
    geom_point()+
    theme(text = element_text(family="Roboto Condensed"))
ggsave("test2.pdf", plot=p,  width=4, height=4)
embed_fonts("test2.pdf",outfile="test2.pdf")

Below includes what was in my console (including the warning message:

> library(ggplot2)
> library(extrafont)
>
> fonts()
[1] "DejaVu Sans"            "DejaVu Sans Condensed"  "DejaVu Sans Light"
[4] "Roboto Condensed"       "Roboto Condensed Light"
>
> V1 <- sample(1:1000,512)
> V2 <- sample(1:1000,512)
> df2 = as.data.frame(cbind(V1,V2))
> p <- ggplot(df2, aes(V1, V2)) +
+     geom_point()+
+     theme(text = element_text(family="Roboto Condensed"))
> ggsave("test.pdf", plot=p,  width=4, height=4)
> embed_fonts("test.pdf",outfile="test.pdf")
>
> V1 <- sample(c(-1000:1000),512)
> V2 <- sample(c(-1000:1000),512)
> df2 = as.data.frame(cbind(V1,V2))
> p <- ggplot(df2, aes(V1, V2)) +
+     geom_point()+
+     theme(text = element_text(family="Roboto Condensed"))
> ggsave("test2.pdf", plot=p,  width=4, height=4)
There were 50 or more warnings (use warnings() to see the first 50)
> embed_fonts("test2.pdf",outfile="test2.pdf")
>
> warnings()
Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x2d
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x2d
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x2d
4: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :

sessionInfo() below

sessionInfo()
R version 3.4.3 Patched (2018-01-20 r74142)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server release 6.9 (Santiago)

Matrix products: default
BLAS: /jhpce/shared/jhpce/core/conda/miniconda-3/envs/svnR-3.4.x/R/3.4.x/lib64/R/lib/libRblas.so
LAPACK: /jhpce/shared/jhpce/core/conda/miniconda-3/envs/svnR-3.4.x/R/3.4.x/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] extrafont_0.17  dplyr_0.7.4     purrr_0.2.4     readr_1.1.1     tidyr_0.7.2     tibble_1.4.1
[7] ggplot2_2.2.1   tidyverse_1.1.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.14     compiler_3.4.3   cellranger_1.1.0 pillar_1.0.1     plyr_1.8.4
 [6] bindr_0.1        forcats_0.2.0    tools_3.4.3      lubridate_1.6.0  jsonlite_1.5
[11] nlme_3.1-131     gtable_0.2.0     lattice_0.20-35  pkgconfig_2.0.1  rlang_0.1.6
[16] psych_1.7.8      parallel_3.4.3   haven_1.1.0      bindrcpp_0.2     Rttf2pt1_1.3.5
[21] xml2_1.1.1       stringr_1.2.0    httr_1.3.1       hms_0.4.0        grid_3.4.3
[26] glue_1.2.0       R6_2.2.2         readxl_1.0.0     foreign_0.8-69   extrafontdb_1.0
[31] modelr_0.1.1     reshape2_1.4.3   magrittr_1.5     scales_0.5.0     rvest_0.3.2
[36] assertthat_0.2.0 mnormt_1.5-5     colorspace_1.3-2 labeling_0.3     stringi_1.1.6
[41] lazyeval_0.2.1   munsell_0.4.3    broom_0.4.3