I am continuing my earlier post here:
Beginner's questions (figures, bibliography) with Sweave/R/LaTeX---my first document
The working code is reproduced here:
\documentclass[a4paper]{article}
\usepackage{Sweave} %%%%%%
\begin{document}
<<echo=TRUE>>=
x <- rnorm(100)
xm <- mean(x)
xm
@
<<echo=FALSE>>=
x <- rnorm(100)
xm <- mean(x)
xm
@
<<echo=TRUE>>=
##### Remove all comments from your data file
test.frame<-read.table(file="apples.d",header=T,sep= "")
names(test.frame)
head(test.frame)
class(test.frame)
@
\begin{figure}[htbp]
\begin{center}
\setkeys{Gin}{width=0.5\textwidth}
<<echo=FALSE,fig=TRUE,width=4,height=4>>=
#### Must tell plot where to get the data from. Could also use test.frame$year
with(test.frame,plot(year,value))
@
\end{center}
\end{figure}
\end{document}
The above runs fine with RStudio (latest) and Tinn-R (latest) and the desired pdf document is produced.
Questions:
If I name the above file as
goodex.snwand I run Sweave, I get the filegoodex-004.pdfwith eitherTinn-RorRStudioas the PDF image of the plot. Why the trailing004? Can this be changed?Can an
EPSfile be produced? Is the tool by which Sweave compiles to PDF is only through (PDF)LaTeX and not through the traditional DVI > PS > PDF route?Just running the command
with(test.frame,plot(year,value))in theRcommand window generates more values on the y-axis i.e. 15000, 20000, 25000 and 30000. However in the PDF file produced by Sweave by my code at the top of this post, I do not get all the values on the y-axis (only 15000 and 25000). How to control the size of the plot directly in the code so that all necessary y values appear?
Update: the file apples.d contains:
#Number of apples I ate
year value
8 12050 #year 2008
9 15292 #year 2009
10 23907 #year 2010
11 33997 #year 2011