View source: R/combine_plots.R
combine_plots | R Documentation |
This function combines two plots build with ggplot2 and use both legends.
combine_plots(plot1, plot2)
plot1 |
First plot to draw. |
plot2 |
Second plot that will be drawed over the first. |
A gtable object.
library(ggplot2) df <- mtcars[, c("disp", "qsec", "cyl")] plot1 <- ggplot(df, aes(x=cyl, y=qsec)) + geom_point() + theme_bw() plot2 <- ggplot(df, aes(x=disp, y=qsec, color = factor(cyl))) + geom_line() + theme_void() + theme(legend.position = c(0.9, 0.8)) cb <- combine_plots(plot1, plot2) plot(cb)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.