[R] does qplot works with Sweave?

Felipe Carrillo mazatlanmexico at yahoo.com
Tue Oct 28 21:43:37 CET 2008


Hi Hadley:
I'm practicing writing a document using MikTex but can't make qplot to execute. It works when using 'plot' though. Is this a normal behaviour?


\documentclass[9pt]{article}
 \title{ggplot2 example}

\begin{document}

\maketitle
\section*{Examples of using ggplot2}
 The goal is to be able to import ggplot2 graphics into the annual report.
Hadley Wickham has done a great job by creating this free R package.
Let's get some data into R from one the built-in packages:
 We'll work with the diamonds data. This dataset is really large, it accounts for
over 50.000 records. We will demostrate  how to create nice and colorful graphics
as well as creating some nice tabular tables with  horizontal and vertical lines.

 <<dataAnalysis.R,echo=F>>=
data(diamonds)
attach(diamonds)
dsmall <- diamonds[sample(nrow(diamonds),1000),]
@
\begin{figure}[h]
<<fig.R,echo=FALSE,fig=TRUE,width=6,height=7>>=
qplot(carat,price,data=dsmall,colour = color)  #THIS CODE DOESN'T WORK
@
\end{figure}


Felipe D. Carrillo  
Supervisory Fishery Biologist  
Department of the Interior  
US Fish & Wildlife Service  
California, USA



More information about the R-help mailing list