0

I have a R code block in a knitr document (.Rnw) that calls two functions draw.hist and plot.timeseries, of which each is supposed to create a different plot.

# HEADER

\documentclass{article}
\usepackage[default]{lato}
\usepackage[T1]{fontenc}
\usepackage[sc]{mathpazo}
\usepackage{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\setcounter{secnumdepth}{1}
\setcounter{tocdepth}{2}
\usepackage{url}
\usepackage[unicode=true,pdfusetitle,
        bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=1,
        breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
{hyperref}
\hypersetup{
pdfstartview={XYZ null null 1}}


# HERE I START DRAWING

<<test, echo = FALSE, warning = FALSE, fig.width=5, fig.height = 3 >>=
draw.hist(data$c1, "test_name_1")
plot.timeseries(data$c1)
@

I know that I could create two separate R blocks, but this is not an option for me.

How can I add line breaks between the two plots?

(I couldn't find anything suitable in the Chunk options. )

enter image description here

rmuc8
  • 2,869
  • 7
  • 27
  • 36
  • 1
    It seems that new options have been added to knitr : `fig.ncol` and `fig.sep`. See [here](https://yihui.name/knitr/options/#plots). You would then use `fig.ncol=1` or similarly `fig.sep=c('\\newline','\\newline')`. As far as I can see it was not in version 1.17 but is in 1.20 so you might need to update knitr or even install the development version. See [here](https://github.com/yihui/knitr/#installation) for the commands. – Luc M Dec 01 '17 at 18:59

2 Answers2

3
\documentclass{article}
\begin{document}

<<echo = FALSE, fig.height = 3>>=
plot(1)
asis_output("\\\\[2cm]")
plot(2)
@

\end{document}

This adds a line break with 2cm of additional whitespace between the plots. Note that each backslashes is escaped by an additional backslash, therefore \\ becomes \\\\.

CL.
  • 14,577
  • 5
  • 46
  • 73
  • Your answer looks reasonable, but I still get exactly the same output. – rmuc8 Jan 04 '16 at 14:57
  • Hm ... the example in my answer works as expected, right? (Try removing the line between the plots or modifying the "2cm".) If there's something else going on in your document, please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – CL. Jan 04 '16 at 14:59
  • Thanks. I included the header. If I remove anything but `\documentclass{article}` from the header, your idea seems to work well - as does other stuff I tried before ;-( Thanks – rmuc8 Jan 04 '16 at 15:23
  • You should add `\begin{document}` before the chunk and `\end{document}` after it. [Like this](http://pastebin.com/ivytMzz9). – CL. Jan 04 '16 at 15:29
  • Thanks, but this was not the problem. – rmuc8 Jan 04 '16 at 18:19
  • It that was not the problem, then the code in the question doesn't reflect your problem. Anyways, I'm not sure if I understand you correctly: Has the problem been solved (if so, how?) or are you still looking for a solution? In the latter case, what exactly *is* the problem? – CL. Jan 04 '16 at 18:29
0

Is there an option that you could use an external CSS and increase the margin? Or my quick and dirty solution would be to paste a bunch of <br> tags?

AlexT
  • 144
  • 8
  • 1
    The chunk syntax indicates that this is a RNW (not RMD) file. Therefore, HTML won't work. (My answer is basically the same as yours, but the LaTeX version of it.) – CL. Jan 04 '16 at 14:50
  • Ok, yes, i totally agree! use the solution from CL! – AlexT Jan 04 '16 at 14:51