【问题标题】:rmarkdown ggplot tufte theme background colorrmarkdown ggplot tufte 主题背景色
【发布时间】:2021-09-23 12:38:58
【问题描述】:

在带有 tufte 主题的 Rmarkdown 中,当我使用 ggplot2 时,我看到背景是白色的,并且与 html 文件的背景颜色不混合。见下文。在ggplot2 中使用透明没有帮助。

有没有办法让ggplot2 的背景与Rmarkdow 中带有tufte 主题的html 文件的背景混合。见下文

【问题讨论】:

标签: r ggplot2 r-markdown


【解决方案1】:

我没有找到将 ggplot 的背景设置为 100% 透明或 NULL 的方法。但是你可以在 ggplot 对象的theme 中定义plot.backgroundlegend.background,使其与knit'ed html 的样式兼容。例如在这个ggplot中,导致this render

```{r fig-margin, fig.margin = TRUE, fig.cap = "MPG vs horsepower, colored by transmission.", fig.width=3.5, fig.height=3.5, cache=TRUE, message=FALSE}
library(ggplot2)
mtcars2 <- mtcars
mtcars2$am <- factor(
  mtcars$am, labels = c('automatic', 'manual')
)
ggplot(mtcars2, aes(hp, mpg, color = am)) +
  geom_point() + geom_smooth() +
  theme(legend.position = 'bottom',
        plot.background = element_rect(fill = "#fffff8"),
        legend.background = element_rect(fill = "#fffff8"))
```

我从here获取了.Rmd代码

【讨论】:

    猜你喜欢
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    • 2018-06-19
    • 1970-01-01
    • 2017-04-23
    相关资源
    最近更新 更多