Just as the title. I have a plot.
p <- ggplot(mtcars) +
geom_point(aes(hp, wt, colour = mpg)) +
ggtitle('Plot 3')
When I use +
to combine plots, I can collect legend.
p + p + plot_layout(guides = 'collect')
When I use |
to combine plots, I can NOT collect legend.
p | p + plot_layout(guides = 'collect')
I do not why.
What is the difference between |
and +
, and When use |
, when use +
.
Any help will be highly appreciated.
This is because of how the nesting level is calculated according to operator precedence.
is interpreted as
Whereas
is interpreted as
Whereas you want