使用 Waffle Chart 和 Glyphs FAILURE 编译 RMarkdown PDF。包括 MWE

Compile RMarkdown PDF with Waffle Chart and Glyphs FAILURE. MWE included

我无法使用 RMarkdown、waffle 包和 glyphs 编译 PDF

我用TIKZ设备还是PDF渲染都无所谓。该文档编译成 HTML.

没有问题

我现在能想到的唯一解决方法是使用 HTML 编译器创建 SVG 图形,然后在我的中间 .TEX 文件中引用这些文件。

请注意,如果您只是 运行 行下方的代码,“## ---- waffle_figure ----”。它应该创建图表,因为您之前已经 installed the fontawesome font on your system,在 R 中安装了 extrafont 包,并且 运行 font_install()命令。

---
title: "Waffle"
output:
  pdf_document:
    latex_engine: xelatex
  html_document: default
header-includes:
- \usepackage{fontspec}
- \defaultfontfeatures{Extension = .otf}
- \usepackage{fontawesome}
- \usepackage{tikz}
---

```{r setup, include=FALSE}
library(knitr)
library(tikzDevice)
knitr::opts_chunk$set(warning = FALSE,  error = FALSE, message = FALSE,  results='hide', echo = FALSE, dev = "tikz", external = TRUE)
```

\faTwitter

## Waffle Plot

You can also embed plots, for example:  \newline

```{r pressure, echo=FALSE, dev="tikz"}
## ---- waffle_figure ----
loadpackages <- function(package.list = c("ggplot2", "Rcpp")) {
    new.packages <- package.list[!(package.list %in% installed.packages()[,"Package"])]
    if (length(new.packages)){install.packages(new.packages, repos = 'http://cran.us.r-project.org')}
    lapply(eval(package.list), require, character.only = TRUE)}

loadpackages(c("waffle", "extrafont", "grid", "gridExtra", "tikzDevice"))
parts <- c(40, 30, 20, 10)
waffle(parts,
       rows=10,
       use_glyph = "user",
       glyph_size = 5)
```

Waffle 包现已更新!现在,quartz 和 cairo 设备都可以使用 knitr/rmarkdown。非常感谢 是 Bob Rudis 和 Dave Gandy 的功劳。

修改后的代码包括拉丁现代 (LaTeX) 字体,以证明可以在华夫饼图表中实现 Latex 字体和 fontawesome 字形。

为了使代码正常工作,您必须先安装 lmroman10-regular-webfont.ttffontawesome-webfont.ttf 来自他们各自的网站:Click on the webfont kit link and Fontawesome download.


title: "Waffle"
output:
  pdf_document:
    latex_engine: xelatex
  html_document: default
header-includes:
- \usepackage{fontspec}
- \defaultfontfeatures{Extension = .otf}
- \usepackage{fontawesome}
- \usepackage{tikz}
---

```{r setup, include=FALSE}
library(knitr)
knitr::opts_chunk$set(warning = FALSE,  error = FALSE, message = FALSE,  results='hide', echo = FALSE, dev = "tikz", external = TRUE)
```

## Font Awesome Gyphy

Font awesome glyphs are easy to integrate into the main text. For example: \faTwitter.

## Waffle Plot

You can also embed plots with glyphs and custom fonts, for example:  \newline

```{r pressure, echo=FALSE, dev="quartz_pdf", dev.args=list(family = "Helvetica")}
## ---- waffle_figure ----
loadpackages <- function(package.list = c("ggplot2", "Rcpp")) {
    new.packages <- package.list[!(package.list %in% installed.packages()[,"Package"])]
    if (length(new.packages)){install.packages(new.packages, repos = 'http://cran.us.r-project.org')}
    lapply(eval(package.list), require, character.only = TRUE)}

loadpackages(c("waffle", "extrafont", "grid", "gridExtra"))
# font_import()  # Run this command, type "y", and press enter after installing new fonts.

parts <- c(40, 30, 20, 10)
waffle(parts,
       rows=10,
       use_glyph = "user",
       glyph_size = 7)+ggtitle("Some Sample Text Here")+
  theme(plot.title = element_text(family="LM Roman 10"))
```