knitr - How to align code and plot side by side

前端 未结 3 1118
半阙折子戏
半阙折子戏 2021-02-20 11:25

is there a simple way (e.g., via a chunk option) to get a chunk\'s source code and the plot it produces side by side, as on page 8 (among others) of this document?

I tri

3条回答
  •  无人及你
    2021-02-20 12:02

    You can display the text in a 'textplot' from package PerformanceAnalytics or gplots.

    (Little) downside: To my knowledge there is no Syntax highlighting possible.

    Sample Code:

    ```{r fig.width=8, fig.height=5, fig.keep = 'last', echo=FALSE}
    suppressMessages(library(PerformanceAnalytics))
    layout(t(1:2))
    textplot('plot(1:10)')
    plot(1:10)
    ```
    

提交回复
热议问题