Hey, there's plenty of examples out there. You can take a look at patchwork if you want to go the ggplot way. Here is a simple example creating a function that allows you having two (old fashion) plots on the same device, the key is on the par function:
rm(list = ls())
# Some example data
set.seed(12)
dat <- data.frame(
year = rep(2010:2015, 50),
x = rnorm(length(rep(2010:2015, 50)))
)
# A function that creates two plots, you can define this function
# in your -ui.R- file
twoplots <- function(dat, by, cols) {
# We change the plotting parameters
oldpar <- par(no.readonly = TRUE) # This stores the current parameters
on.exit(par(oldpar)) # This makes sure to restore them once we are done
par(mfrow = c(1,2)) # This sets the new parameters: 2 columns (plots)
# Plotting the first
with(dat,
plot(x[year == by[1]], type="b", col = cols[1])
)
# Plotting the second
with(dat,
plot(x[year == by[2]], type="b", col = cols[2])
)
}
# Suppose that the user picked years 2011 and 2014
years <- c(2011, 2014)
cols <- c("tomato", "steelblue")
# Calling the function!
twoplots(dat, years, cols)
HIT