How to change the default font in ggplot 2
Hi!
I want to change the font of my scatterplot created with ggplot2
and use Arial as font.
I did first check the default font so I did:
windowsFonts()
And I get:
$serif
[1] "TT Times New Roman"
$sans
[1] "TT Arial"
$mono
[1] "TT Courier New"
So this means that the default font it Times New roman? if so, how do I change it with Arial?
If I understood correctly, I should use extrafont
package but when I try to import the fonts it doesn’t work (it gives me No FontName. Skipping
error). here my code:
install.packages("extrafont")
library(extrafont)
font_import()
So I did try use an older version of Rttf2pt1
:
library(remotes)
remotes::install_version("Rttf2pt1", version = "1.3.8")
and it loaded OK but when I try to import the font I get:
Scanning ttf files in C:WINDOWSFonts ...
Extracting .afm files from .ttf files...
Error in ttf_extract(ttfiles) :
lazy-load database 'N:/R/win-library/4.1/Rttf2pt1/R/Rttf2pt1.rdb' is corrupt
In addition: Warning message:
In ttf_extract(ttfiles) : internal error -3 in R_decompress1
so I am not sure what I am doing wrong but I am also not sure this is the best way to do since all the post I’ve found are pretty old so maybe new fast method/package exist.
Can you help me with this error or do you know if there is a simpler way to change the font in ggplot2
?
Thank you!
Camilla
• 23 views
Read more here: Source link