Skip to content

Instantly share code, notes, and snippets.

@1beb
Created June 20, 2011 05:24
Show Gist options
  • Save 1beb/1035166 to your computer and use it in GitHub Desktop.
Save 1beb/1035166 to your computer and use it in GitHub Desktop.
Part V: ggplot2 introduction, scorecards
## Title: ggplot2 Introduction: Part IV
## Description: This line by line analysis, provides an introduction to ggplot2. Scorecards
## Created by: Brandon Bertelsen: Research Manager, Credo Consulting Inc.
## Save plots as objects
p1 <- ggplot(d, aes(clarity, price)) + geom_boxplot()
p2 <- ggplot(d, aes(price)) + geom_histogram() + facet_grid(~cut)
p3 <- ggplot(d, aes(price, carat, color=clarity)) + geom_point()
# Function courtesy of Hadley Wickham
vplayout <- function(x, y) viewport(layout.pos.row=x, layout.pos.col=y)
grid.newpage()
pushViewport(viewport(layout=grid.layout(4,12)))
# Print them to the viewport
print(p1,vp=vplayout(3:4,1:6))
print(p2,vp=vplayout(1:2,1:12))
print(p3,vp=vplayout(3:4,7:12))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment