combine_plots: Combine plots

Description Usage Arguments Value Examples

View source: R/combine_plots.R

Description

This function combines two plots build with ggplot2 and use both legends.

Usage

1
combine_plots(plot1, plot2)

Arguments

plot1

First plot to draw.

plot2

Second plot that will be drawed over the first.

Value

A gtable object.

Examples

1
2
3
4
5
6
7
8
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)

rsnotivoli/agroclim documentation built on March 21, 2020, 12:22 a.m.