gglegend | R Documentation |
add manual setting legend
gglegend(mapping, data, geom, p = NULL)
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. |
add additional legend to a ggplot
a ggplot object
Guangchuang Yu
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.