Cuurently I am working on a R Sweave report. And I am having some difficulties with the ggplot dimensions in the sweave pdf output. My code:
\documentclass{report}
\begin{document}
demo demo demo demo demo demo demo demo demo demo demo demo
\begin{figure}[h]
\begin{center}
<<echo=FALSE, fig=TRUE>>=
require(ggplot2)
df <- data.frame(a= c(1:10), b = c (10:1))
ggplot(data = df, aes(a, b)) + geom_line()
@
\caption{caption}
\end{center}
\end{figure}
demo demo demo demo demo demo demo demo demo demo demo demo
\end{document}
Now I want to control the plot width and height dimensions in the pdf output. actually I want to keep the height the same but make the width as the same as the text width.
Thanks for your time.
You could try using the knitr
package. (Full Disclosure: I am a minor contributor to the codebase of this package), which allows you to specify out.width
, which controls the width of the figure. So, you could rewrite your code chunk as
<<echo=FALSE, out.width = '0.9\\textwidth'>>=
suppressMessages(require(ggplot2))
df <- data.frame(a= c(1:10), b = c (10:1))
ggplot(data = df, aes(a, b)) + geom_line()
@
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With