R Markdown中的图形大小 [英] Figure size in R Markdown

查看:1021
本文介绍了R Markdown中的图形大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图谨慎而透彻,在网络上阅读有关如何在R Markdown中设置数字格式的各种内容.它们已正确绘制,但似乎无法控制它们的大小.

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 be controlled.

首先,有一些基本知识,例如:

Firstly, there are basics, like:

```{r Fig1, echo=FALSE, 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 Fig1b, echo=FALSE, fig.height=5, fig.width=15, out.retina=1}

```

如果我尝试匹配另一个简单图形的大小,差异是显而易见的.例如:

And if I try to match size of another, simple figure, differences are quite visible. For example:

```{r Fig2, echo=FALSE, fig.height=5, fig.width=5, retina=1}
    par(mfrow=c(1,1), mar=c(4,4,4,1), oma=c(0.5,0.5,0.5,0))
    qqnorm(x1)
```

我想知道对此可以做些什么-即如何使所有数字大小相等?特别是如果像图1和图1b这样的图形缩小了,如何调整如图2所示的简单图形的大小?

I wonder what can be done about it -- i.e., how to make all figures equal in size? In particular, if figures such as Fig1 and Fig1b are shrunk, how to adjust the size of simple figure like in Fig2?

谢谢!

推荐答案

在我看来,您想让Fig2的大小与Fig1中的单个面板的大小相同.如果您确实希望它们的大小相同,建议您为mfrow使用相同的fig.width和相同的值.

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
```

如果您是想让Fig2在渲染的文档上占用与Fig1相同的空间,请尝试在par(op)重设绘图参数的地方进行此操作.

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)
```

这篇关于R Markdown中的图形大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆