Reputation: 4209
When I use ggplot
and when I use stat_smooth()
I get automatic messages like this:
geom_smooth()
using method = 'loess' and formula 'y ~ x
The problem is I use RMarkdown to build a PDF and I want to show some plots there. This message will be shown there like this:
How can I turn this message off? Or any way to not show it on the PDF with the plots.
Upvotes: 9
Views: 13374
Reputation: 53
This 'message' is not a message as far as R markdown is concerned, nor is it a warning. Check out this link for a resolution to this problem.
Upvotes: 0
Reputation: 4416
If rmarkdown is being used then making use of chunk options can be useful. So in your chunk set it like this:
{r warning=FALSE, message=FALSE}
You can turn off warnings and messages for the whole document by running this code in the first chunk:
```{r include=FALSE}
knitr::opts_chunk$set(warning=FALSE, message=FALSE)
```
Upvotes: 9
Reputation: 26695
If you replicate this example in RMarkdown, do you still get the error?
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()
** This prints the warning/info **
Then try changing the final line:
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")
** No warning/info **
Upvotes: 15