Search code examples
rsweavernw

Using ggparcoord in .Rnw file in RStudio


I am trying to create a PDF file (from Sweave .Rnw file in Rstudio).

When I run the code on its own, it seems to work:

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

However, when I try to input this code into the .Rnw file, I get the code outputted, but the image is outputted. I am receiving no errors or warnings, as far as I know.

\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}

Solution

  • This works for me.

    \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}
    

    Notice that I added a fig = TRUE argument into the Sweave chunk. I normally use knitr where such trivialities are handles automatically.

    enter image description here