R> suppressMessages(qplot(1:10, 1:10, geom=c('point', 'smooth')))
`geom_smooth()` using method = 'loess' and formula 'y ~ x'
R> suppressWarnings(qplot(1:10, 1:10, geom=c('point', 'smooth')))
`geom_smooth()` using method = 'loess' and formula 'y ~ x'
I got the above message that I can not suppress. How to turn this message? (I must use qplot() instead of ggplot().)
CodePudding user response:
The issue is that the warning is coming from the printing/rendering, which doesn't happen inside qplot
.
Two ways to fix this:
Add
na.rm=TRUE
:mt <- mtcars mt$cyl[3] <- NA qplot(cyl, disp, data=mt) # Warning: Removed 1 rows containing missing values (geom_point). qplot(cyl, disp, data=mt, na.rm=TRUE) ### (no warning)
Suppress the
print
ing of it, not theqplot
call.mt <- mtcars mt$cyl[3] <- NA gg <- qplot(cyl, disp, data=mt) print(gg) # Warning: Removed 1 rows containing missing values (geom_point). suppressWarnings(print(gg)) ### (no warning)
CodePudding user response:
Maybe we can print
the plot, and suppressMessages
with it.
library(ggplot2)
suppressMessages(print(qplot(1:10, 1:10, geom=c('point', 'smooth'))))