在RStudio中的.Rnw文件中使用ggparcoord

时间:2015-04-13 05:01:34

标签: r sweave rnw

我正在尝试创建一个PDF文件(来自Rstudio中的Sweave .Rnw文件)。

当我自己运行代码时,似乎有效:

library(ggplot2)
library(GGally)
ggparcoord(data.frame(mtcars), columns=1:6, alphaLines=0, boxplot=TRUE, scale="globalminmax") + coord_flip()

但是,当我尝试将此代码输入.Rnw文件时,我会输出代码,但会输出图像。据我所知,我没有收到任何错误或警告。

\documentclass{article}
\usepackage{float, hyperref}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\usepackage{hyperref}

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

\author{myName}
\title{myTitle}

\maketitle

<<options, echo=FALSE>>=
library(knitr)
  opts_chunk$set(cache=TRUE)
@

\section*{Make ggparcoord plot in Sweave}

<<>>=
library(ggplot2)
library(GGally)
ggparcoord(data.frame(mtcars), columns=1:6, alphaLines=0, boxplot=TRUE, scale="globalminmax") + coord_flip()
@

\end{document}

1 个答案:

答案 0 :(得分:0)

这适合我。

\documentclass{article}
\usepackage{float}
\usepackage{hyperref}
\usepackage[margin=1in]{geometry}
\usepackage{hyperref}

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

\author{myName}
\title{myTitle}

\maketitle

<<options, echo=FALSE>>=
library(knitr)
opts_chunk$set(cache=TRUE)
@

\section*{Make ggparcoord plot in Sweave}

<<fig = TRUE>>=
library(ggplot2)
library(GGally)
ggparcoord(data.frame(mtcars), columns=1:6, alphaLines=0, boxplot=TRUE, scale="globalminmax") + coord_flip()
@

\end{document}

请注意,我在Sweave块中添加了fig = TRUE参数。我通常使用knitr来自动处理这些无关紧要的事情。

enter image description here

相关问题