-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Legend Attributes
bhive01 edited this page Sep 23, 2010
·
17 revisions
#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
#color doesn't work, need colour
plot + opts(legend.background = theme_rect(colour = 'purple', fill = 'pink', size = 3, linetype='dashed'))
#color doesn't work, need colour
plot + opts(legend.key = theme_rect(colour = 'purple', fill = 'pink', size = 0.5, linetype='dashed'))
plot + opts(legend.key.size = unit(2, "cm"))
#color doesn't work, need colour
plot + opts(legend.text = theme_text(colour = 'red', angle = 45, size = 10, hjust = 3, vjust = 3, face = 'bold'))
#color doesn't work, need colour
plot + opts(legend.title = theme_text(colour = 'red', angle = 45, size = 10, hjust = 3, vjust = 7, face = 'italic'))
#get rid of the legend
plot + opts(legend.position = 'none')
#move the legend, accepts left, right, top bottom
plot + opts(legend.position = 'left')
#define relative coordinates on plot c(x, y) between 0 and 1
plot + opts(legend.position = c(0.5, 0.5))
#Justification define which side of the legend that the legend.position coordinates refer to
plot + opts(legend.justification = 'right', legend.position=c(0.25,0.3))
#can use left, right, centre or numeric value (0 ≤ x ≤ 1)
(0-1)