Problem with error in ggplot: “Error in grid.Call(”L_textBounds“, as.graphicsAnnot(x$label), x$x, x$y, … ”
I updated my packages, restarted my machine and suddenly it worked. I do not know why, but I am happy that it know works. Thanks a lot to all the contributors - SO is just great!
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font width unknown for character 0x20
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"))
```
Related Topics
Add Error Bars to Show Standard Deviation on a Plot in R
How to Place Grobs with Annotation_Custom() at Precise Areas of the Plot Region
How to Plot with a Png as Background
Difference Between Passing Options in Aes() and Outside of It in Ggplot2
Line Break When No Data in Ggplot2
Ggplot2 Heatmap with Colors for Ranged Values
Avoid Ggplot Sorting the X-Axis While Plotting Geom_Bar()
Remove Groups with Less Than Three Unique Observations
How to Get a Reversed, Log10 Scale in Ggplot2
Combining Bar and Line Chart (Double Axis) in Ggplot2
Getting Strings Recognized as Variable Names in R
What's the Best Way to Use R Scripts on the Command Line (Terminal)
Ggplot Side by Side Geom_Bar()
Align Ggplot2 Plots Vertically
Explain Ggplot2 Warning: "Removed K Rows Containing Missing Values"
How to Use a String Variable to Select a Data Frame Column Using $ Notation