'How to suppress geom_smooth message?
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().)
Solution 1:[1]
The issue is that the message is coming from the printing/rendering, which doesn't happen inside qplot.
Suppress the printing of it, not the qplot call.
gg <- qplot(1:10, 1:10, geom=c('point', 'smooth'))
gg
# `geom_smooth()` using method = 'loess' and formula 'y ~ x'
suppressMessages(print(gg))
### printed, no message
The rendering of a graphic object into a graphic canvas/device happens when the graphic object is printed, not when it is generated. Note that with the first line above (gg <- ...), this does not produce an image/graph of the data, the graphics pane of R is not updated. This happens when one has a "naked" qplot(..) or ggplot(..) + ... on the command line, which returns a grob, and with everything else in an interactive R session, something that is put onto the top-level is always printed (with some print.* method).
Assignment operations to not do this, since the default action is either literally or effectively wrapping the assignment in invisible(..) (which preempts the print-ing of the object).
Solution 2:[2]
qplot is a basic wrapper around ggplot that tries to make it easier to draw ggplots, but the price you pay for simplicity is lack of control in what you are plotting. It might be useful for beginners or for quick exploratory analysis, but ultimately I think using it causes more problems than it solves.
This is particularly true of geom_smooth, where qplot has to guess what smoothing model you want, but won't let you specify it. The best way to suppress the message is to not generate it in the first place by explicitly adding the geom_smooth layer yourself instead of leaving it in the clumsy hands of qplot
library(ggplot2)
qplot(1:10, 1:10, geom="point") + geom_smooth(formula = y ~ x, method = loess)
No message, no warning.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Allan Cameron |

