Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RStudio cannot find fonts to be used in plotting

Tags:

r

rstudio

I'm attempting to plot a simple density plot in RStudio. The plot itself shows up, but with no text and this error message:

50: In doTryCatch(return(expr), name, parentenv, handler) :
no font could be found for family "Arial"

I've tried Googling the answer and several people seem to have had the same problem, without any solutions being found.

I'm running RStudio (version 1.0.153) on a MacBook Pro (High Sierra, 10.13.3)

Here's the full code I am running:

lim <- vector()
xn <- vector()
for (j in 1:1000) {
  ek <- rexp(10000,1)
  i <- 1:10000
  xn <- 1/sqrt(i) * sum(ek) - sqrt(i)
  lim[j] <- xn[10000]
}

plot(density(lim))

I've already tried changing fonts (Helvetica doesn't work either) and resetting the graphics with dev.off().

like image 380
adustybowler Avatar asked Jan 28 '23 15:01

adustybowler


2 Answers

I had this problem recently using High Sierra 10.13.5 RStudio 1.1.453 and R 3.5.0. My plots all showed up without text but worked fine with the same version of R and RStudio on a mac running the previous OS. The command warnings() showed error messages with this text:

no font could be found for family "Arial"

I found that High Sierra has sometimes disabled fonts, even though they are in /Library/Fonts. There is a new app with the OS called Font Book.app. Some details are here.

Looking in the Font Book app, I found that Arial was indeed greyed out and turned off. I chose enable from the popup menu and had to restart the computer before it worked on plots in RStudio and R. Restarting the software wasn't enough.

like image 147
troy Avatar answered Jan 31 '23 07:01

troy


Just want to add a comment in case other users find this help page. I had a very similar issue to OP - Mac OS Mojave 10.14.5, Rstudio 1.1.456 and R 3.6.0

Some additional information on R can not find fonts to be used in plotting

All of base R, lattice and ggplot all could not source font family Arial, so I agree it was a system issue not R specific. I had tried:

  1. Go to Font Book, Arial was greyed out, reactive, restart - no deal
  2. Re-installing all standard fonts in Font Book, restart - no deal
  3. Can workaround calling other font families (eg 'Times') but not a durable solution.
  4. extrafont package and import_font() or font_add() did not work and don't address the root cause

For me: trick was there are separate Font book libraries both for the computer (/Library/Fonts) and each user (/Users/userid/Library/Fonts) - ensure Arial active in both of those, my user font library was empty for some reason (despite restoring standard fonts) - copied fonts from computer font library & problem solved.

like image 22
Brent Avatar answered Jan 31 '23 08:01

Brent