shift_legend: Shift legend to empty space

View source: R/shift_legend.R

shift_legendR Documentation

Shift legend to empty space

Description

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.

Usage

shift_legend(p)

Arguments

p

A ggplot2 object or grob generated from ggplotGrob with empty facet

Value

A grob object to be plotted using grid.draw()

Examples

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))

SCIFoundation/sciCoverageR documentation built on Oct. 31, 2024, 11:45 p.m.