Increasing the size of axis labels in KnitR with R

2019-05-20 15:19发布

问题:

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



标签: r graphics knitr