2016-07-28 3 views
0

.Rnw 비머 프리젠 테이션 내에서 맞춤 글꼴을 사용하고 싶습니다. 오류를 재현 최소한의 작업 예는 다음과 같습니다스웨터와 비머가있는 사용자 정의 ggplot 글꼴

\documentclass{beamer} 
\begin{document} 
\begin{frame}[plain] 
<<echo=FALSE>>= 
library(ggplot2) 
library(extrafont) 
@ 
\begin{figure} 
\centering 
<<label = test, fig=TRUE, include=FALSE, echo=FALSE, message=FALSE>>= 
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() + 
    ggtitle("Fuel Efficiency of 32 Cars") + 
    xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") + 
    theme_bw() + 
    theme(text=element_text(family="Garamond", size=14)) 
@ 
\includegraphics[width=\textwidth]{test} 
\end{figure} 
\end{frame} 
\end{document} 

및 오류 메시지는 다음과 같습니다

Writing to file test.tex 
Processing code chunks with options ... 
1 : keep.source term verbatim (test.Rnw:6) 
Registering fonts with R 
2 : keep.source term verbatim pdf (label = test, test.Rnw:12) 
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 

을하지만 콘솔에서 ggplot 명령을 사용할 때, 모든 것이 잘 보인다.

도움을 주시면 감사하겠습니다.

+0

유일한 방법 내가 .Rnw 파일을 사용하여 오류를 재현 할 수있는, 내가 설치되지 않은 것 글꼴을 사용하려고하면 다음과 같습니다

여기에 작동하는 코드입니다. 콘솔에서 R은 기본 글꼴로 되돌아 가고 제거 된 글꼴을 사용하려고하면 경고를 표시합니다. –

+0

그건 이상합니다. 'fonts()'를 보면 폰트가 설치되어있는 것을 볼 수 있으며'extrafont'에 액세스 할 수 있습니다. – Pascal

답변

0

좋아요, 문제는 실제로 글꼴이 설치되지 않은 것입니다. 그러나 필자는 Garamond만을 예제로 사용했기 때문에 otf 글꼴 Fira Sans를 사용하고 싶었 기 때문에 showtext 패키지를 사용했습니다.

\documentclass{beamer} 
\begin{document} 
\begin{frame}[plain] 
<<test, fig=TRUE, echo=FALSE, width=6, height=4>>= 
library(ggplot2) 
library(showtext) 
font.add.google("Fira Sans", "fira") 
showtext.auto() 
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + 
    ggtitle("Fuel Efficiency of 32 Cars") + 
    xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") + 
    theme_bw() + 
    theme(text = element_text(family = "fira")) 
@ 
\end{frame} 
\end{document}