Legends in ggplot2

May 22, 2011
By

(This article was first published on Shige's Research Blog, and kindly contributed to R-bloggers)

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="")


To leave a comment for the author, please follow the link and comment on his blog: Shige's Research Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.