Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font width unknown for character 0x20

后端 未结 1 1545
感动是毒
感动是毒 2020-12-12 04:23

I would like to use the free font Lato in ggplot2 graphs since the remainder of my R markdown document is set in this font.

The font is installed on my

相关标签:
1条回答
  • 2020-12-12 04:51

    I tried to make it work using extrafont but did not succeed. I am still not quite sure but I think it is a bug. Here is a solution using the package showtext:

    ---
    title: "Embedding Fonts in PDF"
    output: pdf_document
    urlcolor: blue
    ---
    
    ```{r include=FALSE}
    # notice the chunk option 'fig.showtext' that tells R to use the showtext 
    # functionalities for each ne graphics device opened
    knitr::opts_chunk$set(dev = 'pdf', cache = FALSE, fig.showtext = TRUE)
    
    library(ggplot2)
    library(showtext)
    
    font_add(family = "Lato", regular = "/Users/martin/Library/Fonts/Lato-Light.ttf") 
    ```
    
    
    ### Plot with newly set standard font (= Lato) {#lato}
    ```{r echo=FALSE, out.width = '100%'}
    ggplot(mtcars, aes(x=wt, y=mpg)) + 
      geom_point() +     
      ggtitle("Fuel Efficiency of 32 Cars") + 
      xlab("Weight (x1000 lb)") + 
      ylab("Miles per Gallon") + 
      theme(text = element_text(family="Lato"))
    ```
    

    0 讨论(0)
提交回复
热议问题