gglegend {ggfun}R Documentation

gglegend

Description

add manual setting legend

Usage

gglegend(mapping, data, geom, p = NULL)

Arguments

mapping

aes mapping for the 'geom'. The first mapping should be the one for the legend, while others maybe needed for the 'geom' (e.g., label for geom_text).

data

input data frame. If users want to mapping 'VALUE' to 'colour', the input data should contains 'VALUE' and 'colour' (actual value, e.g., 'red' and 'blue') variable.

geom

a geom to plot the data for generating the legend and the geom will be plotted invisible.

p

a ggplot object. If NULL, the 'last_plot()' will be used.

Details

add additional legend to a ggplot

Value

a ggplot object

Author(s)

Guangchuang Yu

Examples

library(ggplot2)
p <- ggplot(mtcars, aes(mpg, disp)) + geom_point()
data <- data.frame(colour = c("red",  "blue"), VALUE = c("A", "B"))
gglegend(aes(colour = VALUE, label=VALUE), data, geom_text, p)

[Package ggfun version 0.1.4 Index]