gpt4 book ai didi

r - knitr、开罗和 ggplot2 : font family 'Source Code Pro' not found in PostScript fontdatabase

转载 作者:行者123 更新时间:2023-12-02 02:46:44 25 4
gpt4 key购买 nike

尝试解决我拥有的 otf 字体问题(请参阅 How to use otf-font in ggplot2 graphics? ),我发现我可以在 ggplot2 中使用这些字体。

将knitr与Rmd文件一起使用是可以的:

---
title: "FontTest"
author: "me"
date: "22. April 2015"
output: html_document
---

```{r, echo=FALSE}
library(ggplot2)

ggplot(mtcars, aes(x=wt, y=mpg, color=factor(gear))) + geom_point() +
ggtitle("Fuel Efficiency of 32 Cars") +
xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
theme(text=element_text(size=16, family="Arial"))
```

但是当我想使用 LaTeX(Rnw 文件)时,我收到错误:

\documentclass{article}

\begin{document}
\SweaveOpts{concordance=TRUE}

<<>>=
Sys.setenv(LANG = "en")
library(ggplot2, quietly=TRUE)
@



<<>>=
ggplot(mtcars, aes(x=wt, y=mpg, color=factor(gear))) + geom_point() +
ggtitle("Fuel Efficiency of 32 Cars") +
xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
theme(text=element_text(size=16, family="Arial"))
@

\end{document}

错误如下:

Writing to file test.tex
Processing code chunks with options ...
1 : echo keep.source term verbatim (test.Rnw:6)
2 : echo keep.source term verbatim (test.Rnw:13)
Error in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, :
invalid font type
Calls: <Anonymous> ... drawDetails -> drawDetails.text -> grid.Call.graphics
In addition: There were 50 or more warnings (use warnings() to see the first 50)
Execution halted

我使用的是 Mac OS X Mavericks。

更新

我找到了使用开罗的解决方法:

\documentclass{article}

\begin{document}



<<>>=
Sys.setenv(LANG = "en")
library(ggplot2, quietly=TRUE)
library(Cairo)
@



<<dev='cairo_pdf'>>=

ggplot(mtcars, aes(x=wt, y=mpg, color=factor(gear))) + geom_point() +
ggtitle("Fuel Efficiency of 32 Cars") +
xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
theme(text=element_text(size=16, family="Source Code Pro"))

@

\end{document}

但现在我收到很多警告:

## Warning in grid.Call(LtextBounds, as.graphicsAnnot(x$label), x$x,x$y, :  font family 'Source Code Pro' not found in PostScript fontdatabase

我想避免抑制这些警告。那么我该怎么做才能消除这些警告呢?

最佳答案

我找到了以下解决方案:

我用

\usepackage{tikz}

<<plot, dev='tikz'>>

在我的 .Rnw 文件中。通过这种方式,我可以在绘图中获得 LaTeX 项目的字体。

关于r - knitr、开罗和 ggplot2 : font family 'Source Code Pro' not found in PostScript fontdatabase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29803524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com