Skip to content

Legend Attributes

bhive01 edited this page Sep 23, 2010 · 17 revisions

Legend(ary) Attributes

Return to opts() list

Base Plot

#create simple dataframe for plotting
x <- 1:10
y <- 10:1
xy <- as.data.frame(cbind(x,y))
xy[[3]] <- c("A","A","A","A","A","B","B","B","B","B")
colnames(xy)[3] <- "type"

#create base plot
plot <- ggplot(data = xy)+
geom_point(aes(x = x, y = y, color=type))

#plot base plot
plot

legend.background (rect)

#color doesn't work, need colour
plot + opts(legend.background = theme_rect(colour = 'purple', fill = 'pink', size = 3, linetype='dashed'))

legend.key (rect)

#color doesn't work, need colour
plot + opts(legend.key = theme_rect(colour = 'purple', fill = 'pink', size = 0.5, linetype='dashed'))

legend.key.size (unit)

plot + opts(legend.key.size = unit(2, "cm"))

legend.text (text)

#color doesn't work, need colour
plot + opts(legend.text = theme_text(colour = 'red', angle = 45, size = 10, hjust = 3, vjust = 3, face = 'bold'))

legend.title (text

#color doesn't work, need colour
plot + opts(legend.title = theme_text(colour = 'red', angle = 45, size = 10, hjust = 3, vjust = 7, face = 'italic'))

legend.position (?)

(x,y vector between 0-1)

legend.justification (?)

(0-1)

Note: The ggplot2 wiki is no longer maintained, please use the ggplot2 website instead!

Clone this wiki locally