我正在尝试使用 knitr 和 tikzDevice 生成直方图以进行投影仪演示。
我已经使用 R-studio 中的控制台生成了直方图,因此看起来数据格式正确,但使用dev=tikz
选项(或“dev=pdf”)编译文档(使用 R-studio)只会产生空白带标题的幻灯片,没有错误(据我所知)。
数据如下所示:
Dag Okt Ar Bes
1 M K 2009 522
2 M Vm 2009 89
3 T A 2009 0
4 T Sg 2009 252
5 T SS 2009 0
6 O Vo 2009 0
7 O St 2009 238
8 O B 2009 107
9 To Vt 2009 249
10 To Tu 2009 121
11 F Sk 2009 415
12 F Tt 2009 0
13 M K 2010 558
14 M Vm 2010 283
15 T A 2010 36
16 T Sg 2010 211
17 T SS 2010 0
18 O Vo 2010 0
19 O St 2010 381
20 O B 2010 164
21 To Vt 2010 260
22 To Tu 2010 99
23 F Sk 2010 397
24 F Tt 2010 19
25 M K 2011 571
26 M Vm 2011 302
27 T A 2011 273
28 T Sg 2011 183
29 T SS 2011 84
30 O Vo 2011 0
31 O St 2011 368
32 O B 2011 53
33 To Vt 2011 298
34 To Tu 2011 92
35 F Sk 2011 346
36 F Tt 2011 30
37 M K 2012 479
38 M Vm 2012 382
39 T A 2012 146
40 T Sg 2012 181
41 T SS 2012 57
42 O Vo 2012 83
43 O St 2012 379
44 O B 2012 54
45 To Vt 2012 507
46 To Tu 2012 173
47 F Sk 2012 238
48 F Tt 2012 55
代码是:
\documentclass{beamer}
\usepackage[norsk]{babel}
\usepackage[utf8]{inputenc}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{pgf}
\usepackage{tikz}
\mode<presentation>
{
\usetheme{Frankfurt}
% or ...
\setbeamercovered{transparent}
% or whatever (possibly just delete it)
}
\title[]{Title}
\subtitle{} % (optional)
\title{Title}
\author{JB}
\date{\today}
\if pdf
\pdfinfo {
/Author (JB)
/Title (Title)
/Subject ()
/Keywords ()
/CreationDate (D:20130531)
}
\fi
\begin{document}
\maketitle
\section{Intro}
\begin{frame}
\frametitle{Test}
\begin{itemize}
\item Test
\end{itemize}
\end{frame}
\section{Data}
% Hidden R code chunk --- reading in the data
<<setup, echo=FALSE,message=FALSE>>=
require(ggplot2)
require(tikzDevice)
histdata<-read.csv("data.csv")
histdata$Ar<-factor(histdata$Ar)
@
\begin{frame}
<<histogram,echo=FALSE,dev=tikz,cache=FALSE>>=
ggplot(histdata,aes(x=Dag,y=Bes,fill=Ar))+geom_bar(position="dodge",stat="identity")+ scale_fill_grey(start=0.8, end=0)
@
\end{frame}
\end{document}