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:\WINDOWS\Fonts ...
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
I did try your code but my plot doesn't change and when I see the
warnings()
it gives mefont family not found in Windows font database
but onC:\Windows\Font\
I have the TTF files there!I did try
fonts()
but I gotNULL
as output (I guess it didn't import any font)And if I do
font_import()
I get:Do you think it could be because of the old version of
Rttf2pt1
since the message error is the same?What happens if you just try:
I still get the same error message saying that the font family not found in Windows font database but I don`t understand why
Perhaps force delete this directory:
Apologies for the late reply but I did try few different things like deleting the folder as you suggested, delete all the packages and re-install them and update others package just in case there was a dependency but I still get the error messages when I do
font_import()
. I got first a pop up message sayingand it does for every font, not for one specific and on R studio: