Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Created June 21, 2013 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ram-N/5833375 to your computer and use it in GitHub Desktop.
Save Ram-N/5833375 to your computer and use it in GitHub Desktop.
Example to understand how facet_wrap and facet_grid work.
library(ggplot2)
unique(diamonds$cut)
unique(diamonds$clarity)
names(diamonds)
dim(diamonds)
g <- ggplot(diamonds[1:1000,]) + geom_point(aes(x=carat, y=price))
g <- g + facet_grid(. ~ cut) #horizontal stacking
g <- g + facet_grid(cut ~ .) #vertical stacking
g <- g + facet_grid(clarity ~ cut) #vertical stacking
g <- g + facet_wrap(clarity ~ cut) #good for exploring interesting cases
g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment