shift_legend | R Documentation |
Function to shift legends into empty facets of a ggplot2 object Ownership of this specific function belongs to Z.Lin (Taken from https://stackoverflow.com/questions/54438495/shift-legend-into-empty-facets-of-a-faceted-plot-in-ggplot2) As far as the authors of this package are aware, this specific function has not been published in a package. Therefore, to aid data visualisation for works by SCIF, this function is compiled into sciCoverageR.
shift_legend(p)
p |
A ggplot2 object or grob generated from ggplotGrob with empty facet |
A grob object to be plotted using grid.draw()
library(ggplot2)
myplot <- ggplot(diamonds, aes(x = carat, fill = cut)) +
geom_density(position = "stack") +
facet_wrap(~ color)
3 libraries required for grid.draw
library(grid)
library(cowplot)
library(gtable)
grid.draw(shift_legend(myplot))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.