当在rmarkdown中增加字体大小以补偿高dpi渲染时,facet wrap 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)
```
theme_light(36)
和theme_light(16)
。你的输出是这些主题选项下图形窗口中交互会话中显示的方式。 - Gregor Thomastheme_light(36)
,而第二个则更改为theme_light(16)
。 - Gregor Thomastheme(strip.text.x = element_text(margin = margin(b = 0, t = 0) ) )
这样写可以达到你想要的效果吗? - aosmith