Skip to content

Instantly share code, notes, and snippets.

@1beb
Created June 20, 2011 01:48
Show Gist options
  • Save 1beb/1035007 to your computer and use it in GitHub Desktop.
Save 1beb/1035007 to your computer and use it in GitHub Desktop.
Part III: ggplot2 introduction, faceting examples
## Title: ggplot2 Introduction: Part 3
## Description: This line by line analysis, provides an introduction to ggplot2. About faceting.
## Created by: Brandon Bertelsen: Research Manager, Credo Consulting Inc.
# Still working with the same dataset, let's revisit some of our earlier plots.
ggplot(d, aes(price)) + geom_histogram()
# Apply a basic facet to view more of your data
ggplot(d, aes(price)) + geom_histogram() + facet_grid(~cut)
# This can be extended further, depending on the number of dimensions you provide to facet
ggplot(d, aes(price)) + geom_histogram() + facet_grid(clarity~cut)
# More complicated graphics are much similar
ggplot(d, aes(carat, price)) + geom_point() + geom_smooth() + facet_grid(~cut)
# Facet grid, doesn't always automatically provide the scale necessary for analysis.
ggplot(d, aes(carat, price)) + geom_point() + facet_wrap(clarity~cut)
# Consider using color to add extra seperation, it works out better than additional facetting
ggplot(d, aes(price, carat, color=clarity)) + geom_point() + facet_grid(~cut)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment