Pey*_*man 9 r ggplot2 r-markdown
当我使用时ggplot,当我使用时,stat_smooth()我会收到如下自动消息:
geom_smooth()使用 method = 'loess' 和公式 'y ~ x
问题是我使用 RMarkdown 构建 PDF,我想在那里显示一些图表。该消息将像这样显示:

我怎样才能关闭此消息?或者任何不将其显示在带有绘图的 PDF 上的方法。
jar*_*rot 15
如果您在 RMarkdown 中复制此示例,您还会收到错误吗?
library(tidyverse)
set.seed(123)
df <- data.frame(group = as.factor(rep(1:3, each = 50)),
week = rep(1:50, 3),
rate = c(round(700 - rnorm(50, 100, 10) - 1:50 * 2, 0),
round(1000 - rnorm(50, 200, 10) - 1:50 * 2, 0),
round(1000 - rnorm(50, 200, 10) - 1:50 * 2, 0)))
df %>%
ggplot(aes(x = week,
y = rate,
group = group,
lty = group)) +
geom_line() +
geom_point() +
geom_smooth()
Run Code Online (Sandbox Code Playgroud)
** 这将打印警告/信息 **
然后尝试更改最后一行:
library(tidyverse)
set.seed(123)
df <- data.frame(group = as.factor(rep(1:3, each = 50)),
week = rep(1:50, 3),
rate = c(round(700 - rnorm(50, 100, 10) - 1:50 * 2, 0),
round(1000 - rnorm(50, 200, 10) - 1:50 * 2, 0),
round(1000 - rnorm(50, 200, 10) - 1:50 * 2, 0)))
df %>%
ggplot(aes(x = week,
y = rate,
group = group,
lty = group)) +
geom_line() +
geom_point() +
geom_smooth(formula = y ~ x, method = "loess")
Run Code Online (Sandbox Code Playgroud)
** 无警告/信息 **
如果使用 rmarkdown,那么使用块选项可能会很有用。所以在你的块中设置如下:
{r warning=FALSE, message=FALSE}
您可以通过在第一个块中运行以下代码来关闭整个文档的警告和消息:
```{r include=FALSE}
knitr::opts_chunk$set(warning=FALSE, message=FALSE)
```
Run Code Online (Sandbox Code Playgroud)