Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF Output #27

Open
leojoubert opened this issue Dec 21, 2017 · 9 comments
Open

PDF Output #27

leojoubert opened this issue Dec 21, 2017 · 9 comments

Comments

@leojoubert
Copy link

leojoubert commented Dec 21, 2017

Hi,

I would like to use hrbdthemes with a PDF output Rmarkdown document. Truing this simple example :

---
title: "hrbrthemes testbed"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(hrbrthemes)
library(tidyverse)

Arial Narrow

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Arial Narrow", subtitle="This is a subtitle") +
  theme_ipsum()

Roboto Condensed

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Roboto Condensed", subtitle="This is a subtitle") +
  theme_ipsum_rc()

I get the following error : 

`Error in grid.Call.graphics : incorrect font specification.`

How can I fix this ?
@hrbrmstr
Copy link
Owner

Thx for trying out the pkg and taking the time to file an issue/question!

Can you post the output of sessionInfo()?

@hrbrmstr
Copy link
Owner

In retrospect, that may not matter.

Please try:

---
title: "hrbrthemes testbed"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r message=FALSE}
library(hrbrthemes)
library(tidyverse)
library(Cairo)

extrafont::loadfonts()
```

### Arial Narrow

```{r dev="cairo_pdf"}
ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Arial Narrow", subtitle="This is a subtitle") +
  theme_ipsum()
```


### Roboto Condensed

```{r dev="cairo_pdf"}
ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Roboto Condensed", subtitle="This is a subtitle") +
  theme_ipsum_rc()
```

@hrbrmstr
Copy link
Owner

And, I just pushed a change that makes this easier.

Assuming RStudio use,

  • File -> New File -> R Markdown
    • From Template
      • ipsum PDF Template

Will start off a new document with everything above so you don't need to cut/paste from other docs.

@hrbrmstr
Copy link
Owner

This was a rly helpful question and will likely ease the pain of many others. If you're inclined, would you mind forking the pkg and adding yourself to the DESCRIPTION file as a contributor? I can do it as well if you provide the necessary DESCRIPTION info fields. No worries if not, but this was a good thing to inquire about and cause the addition for.

@leojoubert
Copy link
Author

Many thinks for having me as a contributor. I forked the repository and added my coordinate. Sorry btw for mistinking typing my answer, it was quite diffucult to read :)

@sahirbhatnagar
Copy link

Any idea how to do this for outputting a single plot to pdf?
I tried

Cairo::CairoPDF("plot.pdf")
ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Roboto Condensed", subtitle="This is a subtitle") +
  theme_ipsum_rc()
dev.off()

But I don't get the robo font.
plot.pdf

@hrbrmstr
Copy link
Owner

I usually do:

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Roboto Condensed", subtitle="This is a subtitle") +
  theme_ipsum_rc() -> gg

ggsave("plot.pdf", gg, device = cairo_pdf)

when targeting PDF

@slyrus
Copy link

slyrus commented Jun 2, 2019

I have a similar problem trying to use roboto condensed (via theme_ipsum_rc) in an Rmarkdown document -> pdf.

@grantmcdermott
Copy link

Just to add a simple solution that worked well for me: Specify cairo_pdf as your dev device for the PDF document. This is especially useful if you plan on exporting to multiple formats and don't want the overhead of switching between (say) PDF and PNG figures for (say) PDF and HTML output.

Example of relevant YAML section:

output: 
  pdf_document:
    dev: cairo_pdf
    <other pdf options>
  html_document:
    <html options>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants