Increasing the size of axis labels in KnitR with R Markdown

非 Y 不嫁゛ 提交于 2019-12-08 02:15:07

问题


In KnitR with R Markdown, I can use dev.args=list(pointsize=18) to pass the pointsize argument to the graphics device.

That increases the size of the points in the plot, and also the amount of space around the plot, but it doesn't seem to affect the size of the axis labels. It seems like I need to use something like par(cex.axis=1.5, cex.lab=1.5), too.

Is that as expected?

Here are three example code chunks with the images produced:

First the defaults:

```{r fig1}
x <- rnorm(100)
y <- 2*x + rnorm(100)
plot(x,y)
```

Now use dev.args=list(pointsize=18)

```{r fig2, dev.args=list(pointsize=18)}
x <- rnorm(100)
y <- 2*x + rnorm(100)
plot(x,y)
```

Now also use par(cex.axis=1.5, cex.lab=1.5)

```{r fig3, dev.args=list(pointsize=18)}
par(cex.axis=1.5, cex.lab=1.5)
x <- rnorm(100)
y <- 2*x + rnorm(100)
plot(x,y)
```


回答1:


Instead of messing with par(cex.blah) endlessly, you can consider vector graphics instead of raster graphics. For example, you can use the SVG device, and scale the plot without quality loss.

```{r fig4, dev='svg', fig.width=6, fig.height=6, out.width='600px'}
x <- rnorm(100)
y <- 2*x + rnorm(100)
par(mar = c(4, 4, .1, .1))
plot(x,y)
```

Update: for the original problem using the png device, the pointsize argument was not passed to the recording device. I have fixed the problem in the development version (>= v1.5.22).



来源:https://stackoverflow.com/questions/21613467/increasing-the-size-of-axis-labels-in-knitr-with-r-markdown

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!