Introduction

Want to generate R ggplot() graphics like all the Ko0L kIdz? But no time to grind through all the references and tutorials? Relax. This compendium of examples will get you up and running, through the miracle of cut and paste. And, if you read the accompanying text, you might get that tutorial thing going, too.

Libraries

Plotting libraries…

library(ggplot2)
library(ggthemes)
library(gridExtra)
library(GGally)

…and some data

library(isdals)

References

Histograms

qplot

First, use qplot() for a quick-and-dirty plot, which has most of the ggplot2 defaults set:

data(iris)
qplot(iris$Petal.Length, geom="histogram")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot2

Then, go full plotgeek with all the ggplot2 options

ggplot(data=iris, aes(iris$Petal.Length)) + 
  geom_histogram(breaks=seq(1, 7, by=0.1), col="blue", fill="green") +
  labs(title="Iris Petal Lengths", x = "length(cm)", y = "frequency") +
  theme_bw(10)