tke*_*win 5 r ggplot2 knitr r-markdown
当增加字体大小以补偿 rmarkdown 中的高 dpi 渲染时,构面包裹 ggplot 图像的标签具有异常大的边距。在下面的示例中,“D”、“E”等上方的垂直空间是我试图降低的。我尝试更改element_text边距以及panel.spacing主题参数。将这些设置为零并不会改变太多事情。
---
title: "PNG facet wrap test"
output:
word_document: default
html_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning=FALSE, message =FALSE,fig.height=4)
knitr::opts_chunk$set(fig.showtext=TRUE)
knitr::opts_chunk$set(fig.width=6.5, fig.height = 4, out.width = 6.5, out.height = 4)
knitr::opts_chunk$set(dev="png", dev.args=list(type="cairo", pointsize=36), dpi=300)
require(ggplot2)
require(dplyr)
```
## Example image
```{r highdpi}
dia = ggplot2::diamonds %>% filter(cut=="Ideal", clarity=="SI2", color!="J")
ggplot(dia, aes(x=carat, y=price)) + facet_wrap(~color) + geom_point() + theme_light(36)
```
Run Code Online (Sandbox Code Playgroud)
在ggplot2_2.2.1中,您可以使用strip.text.x来更改条带的边距margin。(在开发版本中,您可以直接使用 执行此操作strip.text)。
这里我将顶部和底部边距设置为0:
ggplot(dia, aes(x=carat, y=price)) +
facet_wrap(~color) +
geom_point() +
theme_light(36) +
theme(strip.text.x = element_text( margin = margin( b = 0, t = 0) ) )
Run Code Online (Sandbox Code Playgroud)