font use: impossible

Hi -

I moved my largest project onto RStudio Cloud today, hoping I'd be able to use hrbrthemes there (won't work on my Mac). But it doesn't work - and I can't even set the font family in ggplot to "Arial Narrow".

If I do anything to the fonts beside setting a theme (I've been using theme_minimal()), then I get an error.

Here is my plot code, used inside a Rmd document.

  speaker_sfvsi                                %>% 
  ggplot(aes(x = reorder(speaker, SFVSIspeaker), 
             y = SFVSIspeaker,
             fill = gender))                    +
  geom_bar(stat = "identity")                   +
  scale_fill_manual(values = pal)               +
  coord_flip()                                  +
  labs(title = "SFVS index by gender")          +
  theme_minimal()                               +
  theme(text = 
          element_text(family = "Arial Narrow")) 

With the specification of Arial Narrow at the end, it will not work. The error msg. is shown in the attached picture. RStudio_Cloud

The ultimate goal would be to use hrbrthemes. But if I can't have that, I'd be happy simply to be able to specify fonts.

This is all happening inside my project: Posit Cloud

I would appreciate any pointers!

You might be able to explore what fonts are installed by default in using extrafont.

I created a public project to give it a try. If a font you want to use is not available, you may need to install it into your project

Hope that helps!

Thank you, Josh. I did take the extrafont steps, and I am now at a point where -- in RStudio Cloud -- I am able to run the plot code chunk on its own. But I can't knit the document (it is a pdf and I am using the tint package, which is an adjusted version of tufte). When I have any font specification at all in my plots, knitr makes it to the relevant plot code chunk and then just stops. Lately it hasn't even given any errors. It just stops processing.

In my local installation of Rstudio, I have had more luck since I have used font specifications - but not hrbrthemes - and those do get knitted. So what works locally is now not working in RStudio Cloud.

It would be nifty if I could run it on Cloud, since rendering is faster there. But at least I've got something working.

If you have a minimal reprex to share, I'd be happy to experiment with it on cloud.

OK I have done


After that, I run fonts().

My remaining problems are of two sorts:

  • When I specify fonts that are listed in the fonts() overview, most of them are displayed in my output PDFs as something else... a serif default font.
  • When I specify "Arial Narrow" (which I actually want to use) I get an error. This font does not show up when I call fonts(). It's not clear to me how I might install it on RStudio Cloud? When I run the same code locally on the desktop RStudio, it works fine.

You mention installing fonts "into the project" on RStudio Cloud - how would one do that?

A reprex would look as below - keeping in mind that this works fine if run in the GUI - it's the RMD to PDF that doesn't work.

#> Loading required package: tidyverse
dat <- cars
dat %>% 
  ggplot(aes(x = speed,
             y = dist)) +
  geom_point() +
  theme_light(base_family = "Arial Narrow")

Created on 2020-04-28 by the reprex package (v0.3.0)

Any pointers will be appreciated!

I followed these steps:

  • On my Mac I opened the application Font Book.
  • I Right Clicked on Arial Narrow and selected Show In Finder
  • I made note of the directory
  • In, in the Files pane, I selected upload
  • I navigated to /System/Library/Fonts/Supplemental
  • I uploaded Arial Narrow

See the project for the content of the Rmd.

Hope that helps!

Thanks so much for the example; I came here trying to solve a very similar problem. Unfortunately, the code in that sample doesn't quite solve the problem. I have a custom font I am trying to use, and as far as I can tell I have successfully registered it via ttf_import and font_import. It shows up correctly in the output of fonttable(). However, when I try and use it (via setting the text property of the theme() command to be the same as the FamilyName entry for the font in fonttable()'s output), nothing happens.

This works just fine (i.e., the font text appears in Courier):

ggplot(iris, aes(Sepal.Length, Sepal.Width, color=Species)) +
geom_point(size=3) +

But this does not (the font remains in the ggplot default font):

ggplot(iris, aes(Sepal.Length, Sepal.Width, color=Species)) +
geom_point(size=3) +
theme(text=element_text(family="Zilla Slab"))

And here's the relevant lines of the fonttable() output (sorry, it's being mangled and I don't know how to get it formatted properly):

package	afmfile	fontfile	FullName	FamilyName	FontName	Bold	Italic	Symbol	afmsymfile
NA	ZillaSlab-Bold.afm.gz	/cloud/project/fonts/ZillaSlab/ZillaSlab-Bold.ttf	Zilla Slab Bold	Zilla Slab	ZillaSlab-Bold	TRUE	FALSE	FALSE	NA
NA	ZillaSlab-BoldItalic.afm.gz	/cloud/project/fonts/ZillaSlab/ZillaSlab-BoldItalic.ttf	Zilla Slab Bold Italic	Zilla Slab	ZillaSlab-BoldItalic	TRUE	TRUE	FALSE	NA
NA	ZillaSlab-Italic.afm.gz	/cloud/project/fonts/ZillaSlab/ZillaSlab-Italic.ttf	Zilla Slab Italic	Zilla Slab	ZillaSlab-Italic	FALSE	TRUE	FALSE	NA
NA	ZillaSlab-Regular.afm.gz	/cloud/project/fonts/ZillaSlab/ZillaSlab-Regular.ttf	Zilla Slab	Zilla Slab	ZillaSlab-Regular	FALSE	FALSE	FALSE	NA

Hi Josh -

I looked at your project and noticed that in your sample doc, fonttable() shows a list that includes Arial Narrow. And it's showing there as coming from cloud/project. So that's cool. After uploading the ttf file to the project folder, what do you have to do to register it with R?

When I run my Rmd in your project, I do get Arial Narrow to show up.

When I run it in my project - where Arial Narrow is not listed by fonttable() - I can't get it to show up or, as a matter of fact, to render the document at all.

The line ttf_import("/cloud/project") is what adds it to the fonts database.

Any ideas about what might cause a font to not be available for use, even after being successfully imported via ttf_import()?

I would suggest starting a new topic that contains a reprex that shows your particular issue.

OK, will do. Thanks!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.