The
geom_density_ridges
ggridges
base
message
base
suppressMessages
message('This is a message');
suppressMessages(message('This is a message'));
require('ggplot2');
require('ggridges');
suppressMessages(ggplot(Orange, aes(x=age,y=Tree)) + geom_density_ridges());
Picking joint bandwidth of 319
ggplot
message
message=FALSE
ggridges
bandwidth
suppressMessages
When you call ggplot()
, that command doesn't actually draw a plot -- it creates a ggplot object. Only when that object is printed is a plot actually drawn. When you type an expression in the R console, the default behavior is to call print()
on the result which is why it seems like ggplot()
draws a plot.
Note that the warnings you are experiencing do not occur during the creation of the ggplot object; they occur during the printing of this object. So if you run
suppressMessages(ggplot(...))
that's essentially the same as
print(suppressMessages(ggplot(...)))
when running R in interactive mode. But since no messages are generated by ggplot()
, nothing is suppressed and those messages still appear when the resulting object is printed. To suppress the messages created during printing, you need to wrap the actual print()
statement with suppressMessages()
.
suppressMessages(print(ggplot(...)))