Showing posts with label legend. Show all posts
Showing posts with label legend. Show all posts

Sunday, May 22, 2011

Legends in ggplot2

A simple plot takes a few lines of coding:


g1 <- ggplot(d, aes(birth.year))


g2 <- g1 + geom_line(aes(y=alive0, linetype="Famale")) + 
geom_line(aes(y=alive1, linetype="Male")) + scale_linetype_discrete(name = "")


g3 <- g2 + geom_point(aes(y=alive0, shape="Famale")) + 
geom_point(aes(y=alive1, shape="Male")) + scale_x_continuous("") + scale_y_continuous("Proportion Alive in 1982") + opts(legend.position=c(.24, .95), legend.justification = c(1, 1)) + scale_shape_discrete(name="")


g4 <- g3 + labs(fill="")


Counter