Figure size in R Markdown

后端 未结 1 759
清歌不尽
清歌不尽 2020-12-10 20:22

I tried to be careful and thorough, to read various things on the net on how to format figures in R Markdown. They are plotted correctly, but it seems that their size cannot

相关标签:
1条回答
  • 2020-12-10 20:47

    It seems to me like you want Fig2 to be the same size as a single panel in Fig1. If you really want them to be the same size, I'd suggest using the same fig.width and same value for mfrow.

    ```{r Fig1, echo=TRUE, fig.height=5, fig.width=15}
    x1 = rnorm(100)
    x2 = runif(100)
    x3 = rbeta(100, 1, 1,)
    par(mfrow=c(1,3), mar=c(4,4,4,1), oma=c(0.5,0.5,0.5,0))
    qqnorm(x1)
    qqnorm(x2)
    qqnorm(x3)
    ```
    

    ```{r Fig2, echo=TRUE, fig.height=5, fig.width=15}
    par(mfrow=c(1,3), mar=c(4,4,4,1), oma=c(0.5,0.5,0.5,0)) # same, could omit
    plot.new()   # empty plot
    qqnorm(x1)
    plot.new()   # empty plot
    ```
    

    And if you mean you want Fig2 to take up the same amount of space on the rendered document as Fig1 then try this where par(op) resets the plotting parameters.

    ```{r Fig1, echo=TRUE, fig.height=5, fig.width=15}
    x1 = rnorm(100)
    x2 = runif(100)
    x3 = rbeta(100, 1, 1,)
    op <- par(mfrow=c(1,3), mar=c(4,4,4,1), oma=c(0.5,0.5,0.5,0))
    qqnorm(x1)
    qqnorm(x2)
    qqnorm(x3)
    par(op)
    ```
    

    ```{r Fig2, echo=TRUE, fig.height=5, fig.width=15}
    op <- par(mfrow=c(1,1), mar=c(4,4,4,1), oma=c(0.5,0.5,0.5,0))
    qqnorm(x1)
    par(op)
    ```
    

    0 讨论(0)
提交回复
热议问题