# function for getting legend from the plot
#' @export
get_legend <- function(myggplot){
pdf(NULL) # Workaround for bug in ggplot_gtable causing empty Rplots.pdf to be created
tmp <- ggplot_gtable(ggplot_build(myggplot))
leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
legend <- tmp$grobs[[leg]]
graphics.off()
return(legend)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.