I get the code for plotting with two y-axis from the following website:
https://www.r-bloggers.com/2015/04/r-single-plot-with-two-different-y-axes/
Here is my code after referencing the code in the link:
par(mar = c(5,5,2,5))
with(df, plot(Date, get(element), type="l", col="red3", ylab="beta_mkt"))
par(new = T)
with(df, plot(Date, NBER, type="l", axes=F, xlab=NA, ylab=NA, cex=1.2))
axis(side = 4)
mtext(side = 4, line = 3, "NBER")
This code prints out a plot, but I wanted to save this plot in a variable so I can reference it later. Anyone know how to achieve it?
Thanks.
Gin