\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
% \usetheme{Copenhagen}
% \usetheme{Warsaw}
\usetheme{default}
\useinnertheme{rounded}
\useinnertheme{circles}
\useoutertheme{headshadow}
\usecolortheme{orchid}
\usecolortheme{whale}

\setbeamercolor{item}{fg=black}

\RequirePackage{pgf}

\usepackage{calc}
\usepackage{alltt}
\usepackage{Sweave}
\usepackage{boxedminipage}
\usepackage{ulem}
\usepackage{hyperref}
\usepackage{fancyvrb}

\newcommand{\R}{{\sffamily R}}

\DeclareFixedFont{\almosttiny}{OT1}{cmr}{m}{n}{6}

\renewcommand{\emph}[1]{{\bfseries #1}}
\newcommand{\pkg}[1]{{\bfseries #1}}
\newcommand{\code}[1]{{\ttfamily #1}}
\newcommand{\dfn}[1]{{\bfseries #1}}

\definecolor{greybg}{gray}{0.9}
\definecolor{grey}{gray}{.8}
\definecolor{dkgrey}{gray}{0.5}
\newcommand{\intpic}[3]{
\setlength{\fboxsep}{.1in}
\colorbox{white}{\begin{minipage}[t]{#1}
\vspace{0pt}
\includegraphics[width=#1]{#2}
\end{minipage}\begin{minipage}[t]{\textwidth - #1 - .2in} % .2 = 2 x .1
\vspace{0pt}
\setlength{\parindent}{.1in}
\narrower
~\\
#3 \newline ~
\end{minipage}}}

\begin{document}

<<echo=FALSE>>=
options(continue="  ")
library(grid)
library(lattice)
@

\SweaveOpts{keep.source = true, eps = false}

\title{R Graphics: \\What's in it for You?}
\author{Paul Murrell}
\institute{The University of Auckland}
\date{CSIRO October 2011}

\frame{\titlepage}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{Overview}

\begin{itemize}
\item
R can draw plots ...
\item
... but so can lots of other software.
\end{itemize}

\onslide<2->
\begin{itemize}
\item
So why use R?
\end{itemize}

\onslide<3->
\begin{itemize}
\item
\emph{Customisable, extensible, programmable} graphics
\end{itemize}

\end{frame}


%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{R Plots}

\begin{itemize}
\item
R can draw a wide range of plots.
\end{itemize}

<<latticesrc, echo=FALSE, eval=FALSE>>=
barchart(yield ~ variety | site, data = barley,
         groups = year, layout = c(1,6), stack = TRUE,
         ylab = "Barley Yield (bushels/acre)",
         scales = list(x = list(rot = 45)))
@ 

<<lattice, echo=FALSE, fig=TRUE, include=FALSE>>=
print(
<<latticesrc>>
)
@ 

\begin{center}
\includegraphics[width=3in]{rgraphics-lattice}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{R Plots}

\begin{itemize}
\item
R can draw a wide range of plots.
\end{itemize}

<<ggplot2, echo=FALSE, fig=TRUE, include=FALSE>>=
library(ggplot2)
qplot(disp, mpg, data=mtcars) + facet_wrap(~ gear) + stat_smooth(method="lm")
@ 

\begin{center}
\includegraphics[width=2.5in]{rgraphics-ggplot2}
\end{center}

\end{frame}


%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{R Plots}

\begin{itemize}
\item
R can draw a wide range of plots.
\end{itemize}

<<oz, echo=FALSE, results=hide, fig=TRUE, include=FALSE>>=
library(oz)
library(maps)
ozLines <- ozRegion()
# The sections are as
# follows: 1-7, coastlines of WA(1), NT(2), QLD(3), NSW(4),
# VIC(5), TAS(6) and SA(7) respectively; sections 8-16 are
# internal mainland state boundaries: SA-WA(8), WA-NT(9),
# NT-SA(10), NT-QLD(11), QLD-SA(12), QLD-NSW(13), NSW-SA(14),
# NSW-VIC(15), VIC-SA(16).
makeBdry <- function(lines, rev=NULL) {
    if (is.null(rev)) {
        list(x=unlist(lapply(lines, function(line) line$x)),
             y=unlist(lapply(lines, function(line) line$y)))
    } else {
        list(x=unlist(mapply(function(line, rev) { 
                                 if (rev) {
                                     rev(line$x)
                                 } else {
                                     line$x
                                 }
                             }, lines, as.list(rev))),
             y=unlist(mapply(function(line, rev) { 
                                 if (rev) {
                                     rev(line$y)
                                 } else {
                                     line$y
                                 }
                             }, lines, as.list(rev))))
    }
}
WA <- makeBdry(ozLines$lines[c(1, 8, 9)])
NT <- makeBdry(ozLines$lines[c(2, 11, 10, 9)], 
               rev=c(FALSE, TRUE, TRUE, FALSE))
QLD <- makeBdry(ozLines$lines[c(3, 13, 12, 11)],
                rev=c(FALSE, FALSE, TRUE, FALSE))
NSW <- makeBdry(ozLines$lines[c(4, 15, 14, 13)],
                rev=c(FALSE, FALSE, TRUE, TRUE))
VIC <- makeBdry(ozLines$lines[c(5, 16, 15)],
                rev=c(FALSE, TRUE, TRUE))
TAS <- makeBdry(ozLines$lines[6])
SA <- makeBdry(ozLines$lines[c(7, 8, 10, 12, 14, 16)])
australia <- list(states=list(WA=WA, NT=NT, QLD=QLD, 
                    NSW=NSW, VIC=VIC, TAS=TAS, SA=SA),
                  xrange=ozLines$rangex,
                  yrange=ozLines$rangey)
centre <- function(bdry) {
    # c(mean(range(bdry$x)), mean(range(bdry$y)))
    # From 'maps' package
    centroid.polygon(bdry)
}
australia$centres <- lapply(australia$states, centre)
stateInfo <- read.table("oz.txt", head=TRUE, sep="\t")
pop <- as.numeric(gsub(",", "", stateInfo$Population))
area <- as.numeric(gsub(",", "", stateInfo$Area))
popDens <- pop/area
names(popDens) <- gsub(" +", "", stateInfo$Postal)
par(mar=rep(0, 4))
plot.new()
plot.window(australia$xrange, australia$yrange)
for (i in names(popDens)) {
    polygon(australia$states[[i]], 
            col=hcl(46, 55, 4*popDens[i]))
    cntr <- australia$centres[[i]]
    text(cntr[1], cntr[2], round(popDens[i]),
         col=if (4*popDens[i] < 80) "white" else "black")
}
oz(coast=FALSE, state=TRUE, col="grey", add=TRUE)

@ 

\begin{center}
\includegraphics[width=.5\textwidth]{rgraphics-oz}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{R Plots}

\begin{itemize}
\item
R can draw a wide range of plots.
\end{itemize}

% From ~/Books/RGraphics/RGBook/Web/
\begin{center}
\includegraphics[width=3in]{graph-pkgdep.png}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{R Plots}

\begin{itemize}
\item
We could argue about which software package has the widest range
of plots, but that's just a spitting contest.
\end{itemize}

\begin{itemize}
\item
A more interesting question is this:

\begin{quote}
If the software cannot already create the plot that you want,
what are your options?
\end{quote}
\end{itemize}

\begin{itemize}
\item
One way to characterise R graphics is that it aims to provide
you with \emph{lots} of options.
\item
R graphics is \emph{permissive}.
\end{itemize}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}

<<echo=FALSE>>=
insight <- read.csv("insight.csv", stringsAsFactors=FALSE)
insight$Date <- as.Date(gsub(" - .+$", "", insight$Week))
# Drop Week column and first 4 rows (all zeroes)
insight <- insight[-(1:4), -1]
# Restrict dates
insight <- insight[insight$Date > as.Date("2009-01-01"), ]
# insight <- insight[insight$Date > as.Date("2011-01-01"), ]
library(reshape)
insightDF <- melt(insight, id="Date")
colors <- hcl(seq(0, 270, 90), 80, 60)
insightPlot <- ggplot(insightDF, 
                      aes(x=Date, y=value/100, colour=variable)) + 
    geom_line(size=0.5) +
    scale_y_continuous(name="Level of Interest") +
    scale_colour_manual(values=colors) +
    theme_bw() +
    opts(axis.title.x=theme_blank())
@ 

<<unadornedplot, echo=FALSE, fig=TRUE, include=FALSE, height=4>>=
print(insightPlot)
@ 

\begin{center}
{\includegraphics[width=4in]{rgraphics-unadornedplot}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}

<<echo=FALSE>>=
releases <- read.table("rReleases.txt", sep=":", as.is=TRUE,
                       col.names=c("name", "date"))
releases$date <- as.Date(paste("01,", releases$date, sep=""),
                         format="%d, %B, %Y")
# Get (x, y) from 'insightDF' that is closest to release date
subset <- sapply(releases$date, 
                 function(d) { 
                     min(which(d < insight$Date)) 
                 })
releases$Date <- insight$Date[subset]
releases$Interest <- insight$r.plot[subset]
@ 

% inkscape --export-ps=Cc.logo.circle.ps Cc.logo.circle.svg
<<echo=FALSE, results=hide>>=
library(grImport)
# PostScriptTrace("Cc.logo.circle.ps", "Cc.logo.circle.xml")
cclogo <- readPicture("Cc.logo.circle.xml")
# PostScriptTrace("cc.eps", "cc.xml")
# cclogo <- readPicture("cc.xml")
# grid.picture(cclogo)
ccgrob <- pictureGrob(cclogo)
# grid.newpage()
# grid.draw(ccgrob)

library(png)
cclogoPNG <- readPNG("cc.large.png")
# grid.newpage()
# grid.raster(cclogoPNG)
@ 

<<ggplotscale, echo=FALSE, results=hide>>=
pdf("ggplotScale.pdf", width=7, height=4)
# Scaling information for animation below
source("ggplotScale.R")
dev.off()
@ 

<<logoplot, echo=FALSE, fig=TRUE, include=FALSE, height=4>>=
grid.newpage()
grid.rect(gp=gpar(col="grey50", fill="grey95"))
pushViewport(viewport(y=unit(1, "lines"), 
                      height=unit(1, "npc") - unit(2, "lines"),
                      just="bottom",
                      gp=gpar(cex=1)))
print(insightPlot, newpage=FALSE)
downViewport("panel-3-3")
grid.points(ggplotScaleX(as.numeric(releases$Date), 
                         min(as.numeric(insight$Date)),
                         max(as.numeric(insight$Date))),
            ggplotScaleY(releases$Interest,
                         min(insightDF$value),
                         max(insightDF$value)),
            pch=16, size=unit(1.5, "mm"), 
            gp=gpar(col="black"),
            name=paste("points", i, sep=""))
grid.text(paste("  ", releases$name, " "),
          ggplotScaleX(as.numeric(releases$Date), 
                       min(as.numeric(insight$Date)),
                       max(as.numeric(insight$Date))),
          ggplotScaleY(releases$Interest,
                       min(insightDF$value),
                       max(insightDF$value)),
          default.units="native",
          rot=90,
          gp=gpar(cex=.5, col="black"),
          just="right")
upViewport(0)
grid.rect(y=1, height=unit(1, "lines"), just="top",
          gp=gpar(col=NA, fill="grey50"))
grid.text("Google Insights for Search",
          x=unit(1, "mm"),
          just="left",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.text(Sys.time(), 
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.rect(y=0, height=unit(1, "lines"), just="bottom",
          gp=gpar(col=NA, fill="grey50"))
grid.text("BY-NC-SA",
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.picture(cclogo,
             x=unit(1, "npc") - 
               stringWidth("BY-NC-SA  "),
             y=unit(.5, "lines"), 
             just=c("right"),
             width=unit(1, "char"),
             height=unit(1, "char"),
             use.gc=FALSE, gp=gpar(col=NA, fill="white"))
@ 

\begin{center}
{\includegraphics[width=4in]{rgraphics-logoplot}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{Why Use R?}

\begin{itemize}
\item
What are the features that R graphics provides that make this sort
of customisation possible?
\item
In order to do it (in a simple, 
yet flexible and sophisticated and rational and reproducible fashion)
we need \emph{six} important features:
\begin{enumerate}
\item
The ability to write graphics \emph{code}.
\item
The ability to draw simple shapes (\emph{low-level graphics}).
\item
The ability to draw complex shapes (\emph{modern graphics}).
\item
Access to multiple \emph{coordinate systems}.
\item
The ability to arrange graphical components in a \emph{layout}.
\item
The ability to \emph{query} graphical \emph{objects}.
\end{enumerate}
\end{itemize}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 2}
  \end{pgfpicture}
Low-level Graphics}

\begin{itemize}
\item
R follows a ``painters model'' so that you can always add
more ink to the page (on top of what is already there).
\end{itemize}

<<echo=FALSE>>=
shadowCanvas <- function(n=10) {
    deltas <- unit(seq(2, 0, length=n), "mm")
    greys <- grey(seq(1, .8, length=n))
    for (i in 1:n) { 
        grid.roundrect(x=unit(.5, "npc") + unit(2, "mm"),
                       y=unit(.5, "npc") - unit(2, "mm"),
                       width=unit(.8, "npc") + deltas[i],
                       height=unit(.8, "npc") + deltas[i],
                       r=unit(2, "mm"),
                       gp=gpar(col=NA, fill=greys[i]))
    }
    grid.roundrect(width=.8, height=.8, 
                   r=unit(2, "mm"),
                   gp=gpar(lwd=3, fill="white"))
}
@ 

<<painters1, echo=FALSE, fig=TRUE, include=FALSE>>=
grid.newpage()
shadowCanvas()
grid.circle(x=.4, y=.6, r=.2, 
            gp=gpar(lwd=10, fill="grey"))
@ 

<<painters2, echo=FALSE, fig=TRUE, include=FALSE>>=
<<painters1>>
grid.circle(x=.6, y=.4, r=.2, 
            gp=gpar(lwd=10, fill="black"))
@ 

\hspace*{\fill}
{\includegraphics[width=2in]{rgraphics-painters1}}
\hspace*{\fill}
{\includegraphics[width=2in]{rgraphics-painters2}}
\hspace*{\fill}

\begin{itemize}
\item
A plot is just a whole lot of ink all at once. 
\end{itemize}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 2}
  \end{pgfpicture}
Low-level Graphics}

\begin{itemize}
\item
R follows a ``painters model'' so that you can always add
more ink to the page (on top of what is already there).
\end{itemize}

\vspace{\fill}

<<eval=FALSE>>=
xyplot( ... )
@ 

<<eval=FALSE>>=
grid.text( ... )
@ 

\vspace{\fill}

\begin{itemize}
\item
A plot is just a starting point. 
\end{itemize}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}

<<annotatedplot, echo=FALSE, fig=TRUE, include=FALSE, height=4>>=
print(insightPlot)
downViewport("panel-3-3")
grid.points(ggplotScaleX(as.numeric(releases$Date), 
                         min(as.numeric(insight$Date)),
                         max(as.numeric(insight$Date))),
            ggplotScaleY(releases$Interest,
                         min(insightDF$value),
                         max(insightDF$value)),
            pch=16, size=unit(1.5, "mm"), 
            gp=gpar(col="black"),
            name=paste("points", i, sep=""))
grid.text(paste("  ", releases$name, " "),
          ggplotScaleX(as.numeric(releases$Date), 
                       min(as.numeric(insight$Date)),
                       max(as.numeric(insight$Date))),
          ggplotScaleY(releases$Interest,
                       min(insightDF$value),
                       max(insightDF$value)),
          default.units="native",
          rot=90,
          gp=gpar(cex=.5, col="black"),
          just="right")
@ 

\begin{center}
{\includegraphics[width=2in]{rgraphics-unadornedplot}}
\hspace*{\fill}
{\includegraphics[width=2in]{rgraphics-annotatedplot}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}

<<logoplotpaintersbg, echo=FALSE, fig=TRUE, include=FALSE, height=4>>=
grid.newpage()
grid.rect(gp=gpar(col="grey50", fill="grey95"))
grid.rect(y=1, height=unit(1, "lines"), just="top",
          gp=gpar(col=NA, fill="grey50"))
grid.text("Google Insights for Search",
          x=unit(1, "mm"),
          just="left",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.text(Sys.time(), 
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.rect(y=0, height=unit(1, "lines"), just="bottom",
          gp=gpar(col=NA, fill="grey50"))
grid.text("BY-NC-SA",
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.picture(cclogo,
             x=unit(1, "npc") - 
               stringWidth("BY-NC-SA  "),
             y=unit(.5, "lines"), 
             just=c("right"),
             width=unit(1, "char"),
             height=unit(1, "char"),
             use.gc=FALSE, gp=gpar(col=NA, fill="white"))
@ 

\begin{center}
{\includegraphics[width=2in]{rgraphics-logoplotpaintersbg}}
\hspace*{\fill}
{\includegraphics[width=2in]{rgraphics-logoplot}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 2}
  \end{pgfpicture}
Low-level Graphics}

\begin{itemize}
\item
R provides basic drawing primitives.
\end{itemize}

<<primitives, echo=FALSE, fig=TRUE, include=FALSE, width=10.5>>=
grid.newpage()
shadowCanvas()
pushViewport(viewport(gp=gpar(lwd=10, fill="grey")))
grid.circle(x=.2, y=.7, r=.1)
grid.rect(x=.4, y=.7, width=.15, height=.2)
grid.segments(.55, .8, .65, .6)
grid.text("A", x=.8, y=.7, gp=gpar(fontsize=120))
pushViewport(viewport(xscale=c(-1, 1), yscale=c(-1, 1),
                      x=.2, y=.3, 
                      height=unit(.2, "snpc"),
                      width=unit(.2, "snpc")))
t <- pi/2 + seq(0, 2*pi, 2*pi/5)[-1]
grid.polygon(cos(t), sin(t), default="native")
popViewport()
grid.segments(.35, .2, .45, .4, 
              arrow=arrow(type="closed"),
              gp=gpar(fill="black"))
grid.curve(.55, .2, .65, .4, 
           ncp=8, curvature=.5, square=FALSE,
           arrow=arrow(type="closed"),
           gp=gpar(fill="black"))
pushViewport(viewport(x=.8, y=.3, 
                      height=unit(.2, "snpc"),
                      width=unit(.2, "snpc")))
grid.points(c(.3, .5, .7), c(.1, .5, .9), pch=c(0, 10, 21),
            gp=gpar(lwd=3, cex=2))
@ 

\hspace*{\fill}
{\includegraphics[width=4in]{rgraphics-primitives}}
\hspace*{\fill}

\begin{itemize}
\item
A plot is just a whole lot of basic primitives
(neatly arranged).
\end{itemize}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 2}
  \end{pgfpicture}
Low-level Graphics}

\begin{itemize}
\item
R provides basic drawing primitives.
\end{itemize}

\vspace{\fill}

<<eval=FALSE>>=
grid.circle(x = 0.5,
            y = 0.5,
            r = 0.1,
            gp=gpar(col = "black",
                    lwd = 10,
                    fill = "grey"))
@ 

\vspace{\fill}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}

<<logoplotprimitives1, echo=FALSE, fig=TRUE, include=FALSE, height=4>>=
grid.newpage()
grid.rect(gp=gpar(col="grey50", fill="grey95"))
grid.text("1", gp=gpar(col=rgb(0,0,0,.1), fontsize=120))
@ 

<<logoplotprimitives2, echo=FALSE, fig=TRUE, include=FALSE, height=4>>=
grid.newpage()
grid.rect(gp=gpar(col="grey50", fill="grey95"))
grid.rect(y=1, height=unit(1, "lines"), just="top",
          gp=gpar(col=NA, fill="grey50"))
grid.text("2", gp=gpar(col=rgb(0,0,0,.1), fontsize=120))
@ 

<<logoplotprimitives3, echo=FALSE, fig=TRUE, include=FALSE, height=4>>=
grid.newpage()
grid.rect(gp=gpar(col="grey50", fill="grey95"))
grid.rect(y=1, height=unit(1, "lines"), just="top",
          gp=gpar(col=NA, fill="grey50"))
grid.text("Google Insights for Search",
          x=unit(1, "mm"),
          just="left",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.text(Sys.time(), 
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.text("3", gp=gpar(col=rgb(0,0,0,.1), fontsize=120))
@ 

<<logoplotprimitives4, echo=FALSE, fig=TRUE, include=FALSE, height=4>>=
grid.newpage()
grid.rect(gp=gpar(col="grey50", fill="grey95"))
grid.rect(y=1, height=unit(1, "lines"), just="top",
          gp=gpar(col=NA, fill="grey50"))
grid.text("Google Insights for Search",
          x=unit(1, "mm"),
          just="left",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.text(Sys.time(), 
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.rect(y=0, height=unit(1, "lines"), just="bottom",
          gp=gpar(col=NA, fill="grey50"))
grid.text("BY-NC-SA",
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.text("4", gp=gpar(col=rgb(0,0,0,.1), fontsize=120))
@ 

\begin{center}
{\includegraphics[width=1.6in]{rgraphics-logoplotprimitives1}}
\hspace*{\fill}
{\includegraphics[width=1.6in]{rgraphics-logoplotprimitives2}}
\hspace*{\fill}

\vspace{.5in}
\hspace*{\fill}
{\includegraphics[width=1.6in]{rgraphics-logoplotprimitives3}}
\hspace*{\fill}
{\includegraphics[width=1.6in]{rgraphics-logoplotprimitives4}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 3}
  \end{pgfpicture}
Modern Graphics}

\begin{itemize}
\item
R provides features for general graphics (not just for plots)
like alpha channels, complex paths, and raster images.
\end{itemize}

<<modern1, echo=FALSE, fig=TRUE, include=FALSE>>=
grid.newpage()
shadowCanvas()
grid.circle(x=.4, y=.6, r=.2, 
            gp=gpar(lwd=10, fill=rgb(1,0,0,.5)))
@ 

<<modern2, echo=FALSE, fig=TRUE, include=FALSE>>=
<<modern1>>
grid.circle(x=.6, y=.4, r=.2, 
            gp=gpar(lwd=10, fill=rgb(0,0,1,.5)))
@ 

\hspace*{\fill}
{\includegraphics[width=2in]{rgraphics-modern1}}
\hspace*{\fill}
{\includegraphics[width=2in]{rgraphics-modern2}}
\hspace*{\fill}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 3}
  \end{pgfpicture}
Modern Graphics}

\begin{itemize}
\item
R provides features for general graphics (not just for plots)
like alpha channels, complex paths, and raster images.
\end{itemize}

\vspace{\fill}

<<eval=FALSE>>=
grid.circle(x = 0.5,
            y = 0.6,
            r = 0.2,
            gp=gpar(lwd = 10,
                    rgb(red = 1, green = 0, blue = 0,
                        alpha = 0.5)))
@ 

\vspace{\fill}

\end{frame}


%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 3}
  \end{pgfpicture}
Modern Graphics}

\begin{itemize}
\item
R provides features for general graphics (not just for plots)
like alpha channels, complex paths, and raster images.
\end{itemize}

<<echo=FALSE, results=hide>>=
Rlogo <- readPNG(system.file("img", "Rlogo.png", package="png"))
PostScriptTrace("GNU.ps", "GNU.xml")
GNUlogo <- readPicture("GNU.xml")
@ 

<<modern3, echo=FALSE, fig=TRUE, include=FALSE>>=
grid.newpage()
shadowCanvas()
grid.raster(Rlogo, width=.6)
@ 

<<modern4, echo=FALSE, fig=TRUE, include=FALSE>>=
grid.newpage()
shadowCanvas()
grid.picture(GNUlogo, width=.6)
@ 

\hspace*{\fill}
{\includegraphics[width=2in]{rgraphics-modern3}}
\hspace*{\fill}
{\includegraphics[width=2in]{rgraphics-modern4}}
\hspace*{\fill}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 3}
  \end{pgfpicture}
Modern Graphics}

\begin{itemize}
\item
R provides features for general graphics (not just for plots)
like alpha channels, complex paths, and raster images.
\end{itemize}

\vspace{\fill}

<<eval=FALSE>>=
library("png")
Rlogo <- readPNG(system.file("img", "Rlogo.png", 
                             package = "png"))
grid.raster(Rlogo, 
            x = 0.5, y = 0.5,
            width = 0.8)
@ 

\vspace{\fill}

\end{frame}


%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}

<<echo=FALSE, results=hide>>=
setGeneric("polygonify",
           function(object, ...) {
               standardGeneric("polygonify")
           })
setMethod("polygonify", signature("PictureFill"),
          function(object, ...) {
              polygonGrob(object@x, object@y,
                          default.units="native",
                          gp=gpar(col=NA, fill=object@rgb), ...)
          })
setGeneric("outlineify",
           function(object, ...) {
               standardGeneric("outlineify")
           })
setMethod("outlineify", signature("PictureFill"),
          function(object, ...) {
              n <- length(object@x)
              moves <- names(object@x) == "move"
              lty <- ifelse(moves, "dashed", "solid")[-1]
              gList(textGrob(1:sum(moves), 
                             x=unit(object@x[moves], "native") +
                                 unit(1.2, "mm"),
                             y=unit(object@y[moves], "native") - 
                                 unit(c(1.2, 1.2, -1.2, -0.8), "mm"),
                             gp=gpar(col="black", cex=.5), ...),
                    circleGrob(x=object@x[moves],
                               y=object@y[moves],
                               r=unit(.3, "mm"),
                               default.units="native",
                               gp=gpar(col=NA, fill="black"), ...),
                    segmentsGrob(object@x[1:(n-1)],
                                 object@y[1:(n-1)],
                                 object@x[2:n],
                                 object@y[2:n],
                                 default.units="native",
                                 gp=gpar(col="black", lty=lty), ...))
          })
@ 

<<echo=FALSE>>=
combinePaths <- function(paths) {
  x <- unlist(lapply(paths, function(p) p@x[-length(p@x)]))
  y <- unlist(lapply(paths, function(p) p@y[-length(p@x)]))
  names <- unlist(lapply(paths, function(p) names(p@x)[-length(p@x)]))
  names(x) <- names
  names(y) <- names
  list(new("PictureFill",
            x=x, y=y, rgb="black"))
}
@ 

<<logopath, echo=FALSE, fig=TRUE, include=FALSE, width=9, height=3>>=
cclogoOnePath <- new("Picture",
                     paths=combinePaths(cclogo@paths),
                     summary=cclogo@summary)
cclogoOnePath@summary@numPaths <- 1
grid.newpage()
pushViewport(viewport(layout=grid.layout(1, 3)))
pushViewport(viewport(layout.pos.col=1))
grid.picture(cclogoOnePath, FUN=polygonify)
popViewport()
pushViewport(viewport(layout.pos.col=2))
grid.picture(cclogoOnePath, FUN=outlineify)
popViewport()
pushViewport(viewport(layout.pos.col=3))
grid.picture(cclogo)
popViewport()
@ 

<<logoplotpath, echo=FALSE, fig=TRUE, include=FALSE, width=3, height=1>>=
grid.newpage()
pushViewport(viewport(clip=TRUE))
grid.rect(x=1, y=0, width=2, height=2, 
          just=c("right", "bottom"),
          gp=gpar(lwd=3, col="grey50", fill="grey95"))
grid.rect(y=0, height=unit(1, "lines"), just="bottom",
          gp=gpar(col=NA, fill="grey50"))
grid.text("BY-NC-SA",
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.picture(cclogo,
             x=unit(1, "npc") - 
               stringWidth("BY-NC-SA  "),
             y=unit(.5, "lines"), 
             just=c("right"),
             width=unit(1, "char"),
             height=unit(1, "char"),
             use.gc=FALSE, gp=gpar(col=NA, fill="white"))
@ 

\begin{center}
{\includegraphics[width=3in]{rgraphics-logopath}}
\end{center}

\vspace{.5in}
\begin{center}
{\includegraphics[width=2in]{rgraphics-logoplotpath}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 4}
  \end{pgfpicture}
Coordinate Systems}

\begin{itemize}
\item
Drawing a plot requires working in multiple coordinate systems.
\end{itemize}

<<latticecoord, echo=FALSE, fig=TRUE, include=FALSE, width=4, height=4>>=
library(lattice)
xyplot(1:3 ~ 1:3 | 1)
@ 

\begin{center}
\fbox{\includegraphics[width=.5\textwidth]{rgraphics-latticecoord}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 4}
  \end{pgfpicture}
Coordinate Systems}

\begin{itemize}
\item
Drawing a plot requires working in multiple coordinate systems.
\end{itemize}

<<latticecoordnative, echo=FALSE, fig=TRUE, include=FALSE, width=4, height=4>>=
xyplot(1:3 ~ 1:3 | 1)
# grid.gremove(".*")
grid.rect(gp=gpar(col=NA, fill=rgb(1, 1, 1, .8)))
downViewport("plot_01.panel.1.1.off.vp")
grid.rect(gp=gpar(lwd=3))
grid.xaxis(at=c(1, 3), gp=gpar(lwd=3, fontface="bold"))
grid.yaxis(at=c(1, 3), gp=gpar(lwd=3, fontface="bold"))
@ 

\begin{center}
\fbox{\includegraphics[width=.5\textwidth]{rgraphics-latticecoordnative}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 4}
  \end{pgfpicture}
Coordinate Systems}

\begin{itemize}
\item
Drawing a plot requires working in multiple coordinate systems.
\end{itemize}

<<latticecoordnpc, echo=FALSE, fig=TRUE, include=FALSE, width=4, height=4>>=
xyplot(1:3 ~ 1:3 | 1)
# grid.gremove(".*")
grid.rect(gp=gpar(col=NA, fill=rgb(1, 1, 1, .8)))
downViewport("plot_01.panel.1.1.off.vp")
grid.rect(gp=gpar(lwd=3))
pushViewport(viewport())
grid.xaxis(at=0:1, gp=gpar(lwd=3, fontface="bold"))
grid.yaxis(at=0:1, gp=gpar(lwd=3, fontface="bold"))
@ 

\begin{center}
\fbox{\includegraphics[width=.5\textwidth]{rgraphics-latticecoordnpc}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 4}
  \end{pgfpicture}
Coordinate Systems}

\begin{itemize}
\item
Drawing a plot requires working in multiple coordinate systems.
\end{itemize}

<<latticecoordmm, echo=FALSE, fig=TRUE, include=FALSE, width=4, height=4>>=
xyplot(1:3 ~ 1:3 | 1)
# grid.gremove(".*")
grid.rect(gp=gpar(col=NA, fill=rgb(1, 1, 1, .8)))
downViewport("plot_01.panel.1.1.off.vp")
grid.rect(gp=gpar(lwd=3))
pushViewport(viewport())
grid.xaxis(at=0:1, label=paste(c(0, 10), "mm", sep=""), 
           gp=gpar(lwd=3, fontface="bold"))
grid.yaxis(at=0:1, label=paste(c(0, 10), "mm", sep=""), 
           gp=gpar(lwd=3, fontface="bold"))
@ 

\begin{center}
\fbox{\includegraphics[width=.5\textwidth]{rgraphics-latticecoordmm}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 4}
  \end{pgfpicture}
Coordinate Systems}

\begin{itemize}
\item
Drawing a plot requires working in multiple coordinate systems.
\end{itemize}

<<latticecoordadd, echo=FALSE, fig=TRUE, include=FALSE, width=4, height=4>>=
xyplot(1:3 ~ 1:3 | 1)
grid.rect(gp=gpar(col=NA, fill=rgb(1, 1, 1, .8)))
downViewport("plot_01.panel.1.1.vp")
grid.text("1mm below and right from\ntop-left corner",
          unit(0, "npc") + unit(1, "mm"),
          unit(1, "npc") - unit(1, "mm"),
          just=c("left", "top"))
grid.text("2mm above and right from (1, 1)",
          unit(1, "native") + unit(2, "mm"),
          unit(1, "native") + unit(2, "mm"),
          just=c("left", "bottom"))
@ 

\begin{center}
\fbox{\includegraphics[width=.5\textwidth]{rgraphics-latticecoordadd}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 4}
  \end{pgfpicture}
Coordinate Systems}

\begin{itemize}
\item
Drawing a plot requires working in multiple coordinate systems.
\end{itemize}

\vspace{\fill}

<<eval=FALSE>>=
grid.text("1mm below and right from top-left corner",
          x = unit(0, "npc") + unit(1, "mm"),
          y = unit(1, "npc") - unit(1, "mm"),
          just = c("left", "top"))
@

<<eval=FALSE>>=
grid.text("2mm above and right from (1, 1)",
          x = unit(1, "native") + unit(2, "mm"),
          y = unit(1, "native") + unit(2, "mm"),
          just = c("left", "bottom"))
@ 

\vspace{\fill}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}

\begin{center}
{\includegraphics[width=2in]{rgraphics-unadornedplot}}
\hspace*{\fill}
{\includegraphics[width=2in]{rgraphics-annotatedplot}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 5}
  \end{pgfpicture}
Layout}

\begin{itemize}
\item
Drawing a plot requires being able to arrange multiple coordinate systems.
\end{itemize}

\begin{center}
\fbox{\includegraphics[width=.5\textwidth]{rgraphics-latticecoord}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 5}
  \end{pgfpicture}
Layout}

\begin{itemize}
\item 
Drawing a plot requires being able to arrange multiple coordinate systems.
\end{itemize}

<<latticevps, echo=FALSE, results=hide>>=
pdf("rgraphics-latticevps-%d.pdf", width=4, height=4, onefile=FALSE)
<<latticecoord>>
showViewport(depth=2, col=NA, newpage=TRUE)
downViewport("plot_01.panel.1.1.off.vp")
grid.segments(0, 1, 1, 1, gp=gpar(col=rgb(0,0,1,.2)))
dev.off()
@ 

\begin{center}
\fbox{\includegraphics[width=.5\textwidth]{rgraphics-latticevps-2}}
\end{center}

\end{frame}


%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 5}
  \end{pgfpicture}
Layout}

\begin{itemize}
\item
Drawing a plot requires being able to arrange multiple coordinate systems.
\end{itemize}

<<latticevps, echo=FALSE, results=hide>>=
pdf("rgraphics-latticegrobs-%d.pdf", width=4, height=4, onefile=FALSE)
<<latticecoord>>
showViewport(depth=2, col=NA)
dev.off()
@ 

\begin{center}
\fbox{\includegraphics[width=.5\textwidth]{rgraphics-latticegrobs-1}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 5}
  \end{pgfpicture}
Layout}

\begin{itemize}
\item
Drawing a plot requires being able to arrange multiple coordinate systems.
\end{itemize}

\vspace{\fill}

<<eval=FALSE>>=
pushViewport(viewport(width = 0.5, height = 0.5,
                      name = "plotvp"))
@

<<eval=FALSE>>=
upViewport(1)
@

<<eval=FALSE>>=
downViewport("plotvp")
@

\vspace{\fill}

\end{frame}


%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}

<<vplayer, eval=FALSE, echo=FALSE>>=
pushViewport(viewport())
pushViewport(viewport(y=1, height=unit(1, "lines"), just="top"))
upViewport()
pushViewport(viewport(y=0, height=unit(1, "lines"), just="bottom"))
upViewport(2)
showViewport(col=NA)
grid.segments(0, unit(0:1, "npc") + unit(c(1, -1), "lines"),
              1, unit(0:1, "npc") + unit(c(1, -1), "lines"), 
              gp=gpar(col=rgb(0,0,1,.2)))
@ 

<<logoplotcoords1, echo=FALSE, results=hide>>=
pdf("rgraphics-logoplotcoords1-%d.pdf", height=4, onefile=FALSE)
<<vplayer>>
dev.off()
@ 

<<logoplotcoords2, echo=FALSE, results=hide>>=
pdf("rgraphics-logoplotcoords2-%d.pdf", height=4, onefile=FALSE)
grid.newpage()
pushViewport(viewport(y=unit(1, "lines"), 
                      height=unit(1, "npc") - unit(2, "lines"),
                      just="bottom",
                      gp=gpar(cex=1)))
grid.rect(gp=gpar(col="grey50", fill="grey95"))
print(insightPlot, newpage=FALSE)
downViewport("panel-3-3")
grid.points(ggplotScaleX(as.numeric(releases$Date), 
                         min(as.numeric(insight$Date)),
                         max(as.numeric(insight$Date))),
            ggplotScaleY(releases$Interest,
                         min(insightDF$value),
                         max(insightDF$value)),
            pch=16, size=unit(1.5, "mm"), 
            gp=gpar(col="black"),
            name=paste("points", i, sep=""))
grid.text(paste("  ", releases$name, " "),
          ggplotScaleX(as.numeric(releases$Date), 
                       min(as.numeric(insight$Date)),
                       max(as.numeric(insight$Date))),
          ggplotScaleY(releases$Interest,
                       min(insightDF$value),
                       max(insightDF$value)),
          default.units="native",
          rot=90,
          gp=gpar(cex=.5, col="black"),
          just="right")
popViewport(0)
<<vplayer>>
dev.off()
@ 

<<logoplotcoords3, echo=FALSE, results=hide>>=
pdf("rgraphics-logoplotcoords3-%d.pdf", height=4, onefile=FALSE)
grid.newpage()
pushViewport(viewport(y=unit(1, "lines"), 
                      height=unit(1, "npc") - unit(2, "lines"),
                      just="bottom",
                      gp=gpar(cex=1)))
grid.rect(gp=gpar(col="grey50", fill="grey95"))
print(insightPlot, newpage=FALSE)
downViewport("panel-3-3")
grid.points(ggplotScaleX(as.numeric(releases$Date), 
                         min(as.numeric(insight$Date)),
                         max(as.numeric(insight$Date))),
            ggplotScaleY(releases$Interest,
                         min(insightDF$value),
                         max(insightDF$value)),
            pch=16, size=unit(1.5, "mm"), 
            gp=gpar(col="black"),
            name=paste("points", i, sep=""))
grid.text(paste("  ", releases$name, " "),
          ggplotScaleX(as.numeric(releases$Date), 
                       min(as.numeric(insight$Date)),
                       max(as.numeric(insight$Date))),
          ggplotScaleY(releases$Interest,
                       min(insightDF$value),
                       max(insightDF$value)),
          default.units="native",
          rot=90,
          gp=gpar(cex=.5, col="black"),
          just="right")
popViewport(0)
grid.rect(y=1, height=unit(1, "lines"), just="top",
          gp=gpar(col=NA, fill="grey50"))
grid.text("Google Insights for Search",
          x=unit(1, "mm"),
          just="left",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.text(Sys.time(), 
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
<<vplayer>>
dev.off()
@ 

<<logoplotcoords4, echo=FALSE, results=hide>>=
pdf("rgraphics-logoplotcoords4-%d.pdf", height=4, onefile=FALSE)
grid.newpage()
grid.rect(gp=gpar(col="grey50", fill="grey95"))
pushViewport(viewport(y=unit(1, "lines"), 
                      height=unit(1, "npc") - unit(2, "lines"),
                      just="bottom",
                      gp=gpar(cex=1)))
print(insightPlot, newpage=FALSE)
downViewport("panel-3-3")
grid.points(ggplotScaleX(as.numeric(releases$Date), 
                         min(as.numeric(insight$Date)),
                         max(as.numeric(insight$Date))),
            ggplotScaleY(releases$Interest,
                         min(insightDF$value),
                         max(insightDF$value)),
            pch=16, size=unit(1.5, "mm"), 
            gp=gpar(col="black"),
            name=paste("points", i, sep=""))
grid.text(paste("  ", releases$name, " "),
          ggplotScaleX(as.numeric(releases$Date), 
                       min(as.numeric(insight$Date)),
                       max(as.numeric(insight$Date))),
          ggplotScaleY(releases$Interest,
                       min(insightDF$value),
                       max(insightDF$value)),
          default.units="native",
          rot=90,
          gp=gpar(cex=.5, col="black"),
          just="right")
popViewport(0)
grid.rect(y=1, height=unit(1, "lines"), just="top",
          gp=gpar(col=NA, fill="grey50"))
grid.text("Google Insights for Search",
          x=unit(1, "mm"),
          just="left",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.text(Sys.time(), 
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.rect(y=0, height=unit(1, "lines"), just="bottom",
          gp=gpar(col=NA, fill="grey50"))
grid.text("BY-NC-SA",
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.picture(cclogo,
             x=unit(1, "npc") - 
               stringWidth("BY-NC-SA  "),
             y=unit(.5, "lines"), 
             just=c("right"),
             width=unit(1, "char"),
             height=unit(1, "char"),
             use.gc=FALSE, gp=gpar(col=NA, fill="white"))
<<vplayer>>
dev.off()
@ 

\begin{center}
{\includegraphics[width=1.6in]{rgraphics-logoplotcoords1-1}}
\hspace*{\fill}
{\includegraphics[width=1.6in]{rgraphics-logoplotcoords2-1}}
\hspace*{\fill}

\vspace{.5in}
\hspace*{\fill}
{\includegraphics[width=1.6in]{rgraphics-logoplotcoords3-1}}
\hspace*{\fill}
{\includegraphics[width=1.6in]{rgraphics-logoplotcoords4-1}}
\end{center}

\end{frame}


%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 6}
  \end{pgfpicture}
Graphical Objects}

\begin{itemize}
\item
In R graphics, it is possible to access, query and modify 
components of a plot.
\end{itemize}

\begin{minipage}{.5\textwidth}
\scriptsize
<<latticels, echo=FALSE>>=
print(xyplot(1:3 ~ 1:3 | 1))
grid.ls()
@ 
\end{minipage}%
\begin{minipage}{.5\textwidth}
\begin{center}
\fbox{\includegraphics[width=\textwidth]{rgraphics-latticecoord}}
\end{center}
\end{minipage}%

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 6}
  \end{pgfpicture}
Graphical Objects}

\begin{itemize}
\item
In R graphics, it is possible to access, query and modify 
components of a plot.
\end{itemize}

\vspace{\fill}

<<eval=FALSE>>=
grid.text("BY-NC-SA",
          x = unit(1, "npc") - unit(1, "mm"),
          just = c("right"),
          name = "cclabel")
@

<<eval=FALSE>>=
ccx <- unit(1, "npc") - unit(1, "mm") - 
       grobWidth("cclabel")
@ 

<<eval=FALSE>>=
grid.edit("cclabel", gp=gpar(fontface="bold"))
@ 

\vspace{\fill}

\end{frame}


%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}


<<logoplotgrob1, echo=FALSE, fig=TRUE, include=FALSE, width=3, height=1>>=
grid.newpage()
pushViewport(viewport(clip=TRUE))
grid.rect(x=1, y=0, width=2, height=2, 
          just=c("right", "bottom"),
          gp=gpar(lwd=3, col="grey50", fill="grey95"))
grid.rect(y=0, height=unit(1, "lines"), just="bottom",
          gp=gpar(col=NA, fill="grey50"))
grid.text("BY-NC-SA",
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(.5, "lines"),
          gp=gpar(fontface="italic", col="grey"))
grid.rect(x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(.5, "lines"),
          width=stringWidth("BY-NC-SA"),
          height=stringHeight("BY-NC-SA"),
          gp=gpar(col="red"))
@ 

<<logoplotgrob2, echo=FALSE, fig=TRUE, include=FALSE, width=3, height=1>>=
grid.newpage()
pushViewport(viewport(clip=TRUE))
grid.rect(x=1, y=0, width=2, height=2, 
          just=c("right", "bottom"),
          gp=gpar(lwd=3, col="grey50", fill="grey95"))
grid.rect(y=0, height=unit(1, "lines"), just="bottom",
          gp=gpar(col=NA, fill="grey50"))
grid.text("BY-NC-SA",
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(.5, "lines"),
          gp=gpar(fontface="italic", col="grey"))
grid.rect(x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(.5, "lines"),
          width=stringWidth("BY-NC-SA"),
          height=stringHeight("BY-NC-SA"),
          gp=gpar(col="red"))
grid.picture(cclogo,
             x=unit(1, "npc") - 
               stringWidth("BY-NC-SA  "),
             y=unit(.5, "lines"), 
             just=c("right"),
             width=unit(1, "char"),
             height=unit(1, "char"),
             use.gc=FALSE, gp=gpar(col=NA, fill="white"))
@ 

<<logoplotgrob3, echo=FALSE, fig=TRUE, include=FALSE, width=3, height=1>>=
grid.newpage()
pushViewport(viewport(clip=TRUE))
grid.rect(x=1, y=0, width=2, height=2, 
          just=c("right", "bottom"),
          gp=gpar(lwd=3, col="grey50", fill="grey95"))
grid.rect(y=0, height=unit(1, "lines"), just="bottom",
          gp=gpar(col=NA, fill="grey50"))
grid.text("BY-NC-SA",
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.picture(cclogo,
             x=unit(1, "npc") - 
               stringWidth("BY-NC-SA  "),
             y=unit(.5, "lines"), 
             just=c("right"),
             width=unit(1, "char"),
             height=unit(1, "char"),
             use.gc=FALSE, gp=gpar(col=NA, fill="white"))
@ 

\begin{center}
{\includegraphics[width=2in]{rgraphics-logoplotgrob1}}
\end{center}

\vspace{.15in}
\begin{center}
{\includegraphics[width=2in]{rgraphics-logoplotgrob2}}
\end{center}

\vspace{.15in}
\begin{center}
{\includegraphics[width=2in]{rgraphics-logoplotgrob3}}
\end{center}

\end{frame}


%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{A Bit of Razzmatazz}

% THIS IS VERY SLOW so set eval=TRUE if want to modify
<<logoplotinteractive, echo=FALSE, results=hide, eval=FALSE>>=
pdf("logoplot.pdf", width=7, height=4)
# Main picture
grid.newpage()
grid.rect(gp=gpar(col="grey50", fill="grey95"))
pushViewport(viewport(y=unit(1, "lines"), 
                      height=unit(1, "npc") - unit(2, "lines"),
                      just="bottom",
                      gp=gpar(cex=1)))
print(insightPlot, newpage=FALSE)
downViewport("panel-3-3")
grid.points(ggplotScaleX(as.numeric(releases$Date), 
                         min(as.numeric(insight$Date)),
                         max(as.numeric(insight$Date))),
            ggplotScaleY(releases$Interest,
                         min(insightDF$value),
                         max(insightDF$value)),
            pch=16, size=unit(1.5, "mm"), 
            gp=gpar(col="black"),
            name=paste("points", i, sep=""))
grid.text(paste("  ", releases$name, " "),
          ggplotScaleX(as.numeric(releases$Date), 
                       min(as.numeric(insight$Date)),
                       max(as.numeric(insight$Date))),
          ggplotScaleY(releases$Interest,
                       min(insightDF$value),
                       max(insightDF$value)),
          default.units="native",
          rot=90,
          gp=gpar(cex=.5, col="black"),
          just="right")
upViewport(0)
grid.rect(y=1, height=unit(1, "lines"), just="top",
          gp=gpar(col=NA, fill="grey50"))
grid.text("Google Insights for Search",
          x=unit(1, "mm"),
          just="left",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"),
          name="google")
grid.text(Sys.time(), 
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(1, "npc") - unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.rect(y=0, height=unit(1, "lines"), just="bottom",
          gp=gpar(col=NA, fill="grey50"))
grid.text("BY-NC-SA",
          x=unit(1, "npc") - unit(1, "mm"),
          just="right",
          y=unit(.5, "lines"),
          gp=gpar(fontface="italic", col="white"))
grid.picture(cclogo,
             x=unit(1, "npc") - 
               stringWidth("BY-NC-SA  "),
             y=unit(.5, "lines"), 
             just=c("right"),
             width=unit(1, "char"),
             height=unit(1, "char"),
             use.gc=FALSE, gp=gpar(col=NA, fill="white"),
             name="cc")
library(gridSVG)
# hyperlinks
grid.hyperlink("google", href="http://www.google.com")
grid.garnish("cc", "pointer-events"="all")
grid.hyperlink("cc", href="http://creativecommons.org/")
# Animation
n <- nrow(insight)
x <- animUnit(unit(ggplotScaleX(rep(as.numeric(insight$Date)[unlist(lapply(1:n, seq))], 
                                    4),
                                min(as.numeric(insight$Date)),
                                max(as.numeric(insight$Date))),
                   "native"),
              timeid=rep(rep(1:n, 1:n), 4),
              id=rep(1:4, each=sum(1:n)))                     
y <- animUnit(unit(ggplotScaleY(c(insight$r.plot[unlist(lapply(1:n, seq))],
                                  insight$sas.plot[unlist(lapply(1:n, seq))],
                                  insight$stata.plot[unlist(lapply(1:n, seq))],
                                  insight$spss.plot[unlist(lapply(1:n, seq))]),
                                min(insightDF$value),
                                max(insightDF$value)),
                   "native"),
              timeid=rep(rep(1:n, 1:n), 4),
              id=rep(1:4, each=sum(1:n)))
# Find the right polyline
panelGrobs <- grid.ls(grid.get("panel-3-3"))$name
polylineName <- panelGrobs[grep("GRID.polyline", panelGrobs)]
grid.animate(polylineName, x=x, y=y, duration=5)
# Interaction
panelDepth <- downViewport("panel-3-3")
# Create a viewport exactly like "panel-3-3", but with clipping off
clippedvp <- current.viewport()
clippedvp$clip <- NA
clippedvp$name <- "intervp"
upViewport()
pushViewport(clippedvp, viewport(gp=gpar(cex=.5)))
bar <- textGrob("|", 
                x=unit(.75, "npc"),
                y=unit(1, "npc") + unit(1, "lines"), 
                name="bar")
grid.draw(garnishGrob(bar, visibility="hidden"))
for (i in 1:nrow(insight)) {
    # Data points
    subset <- insightDF$Date == insight$Date[i]
    points <- pointsGrob(ggplotScaleX(as.numeric(insightDF$Date[subset]), 
                                      min(as.numeric(insight$Date)),
                                      max(as.numeric(insight$Date))),
                         ggplotScaleY(insightDF$value[subset],
                                      min(insightDF$value),
                                      max(insightDF$value)),
                         pch=16, size=unit(1.5, "mm"), 
                         gp=gpar(col=colors),
                         name=paste("points", i, sep=""))
    grid.draw(garnishGrob(points, visibility="hidden"))
    # Display above plot
    date <- textGrob(format(unique(insight$Date[i]), format="%B %Y"),
                     x=unit(.75, "npc") + unit(2, "mm"), just="left",
                     y=unit(1, "npc") + unit(1, "lines"), 
                     name=paste("date", i, sep=""))
    grid.draw(garnishGrob(date, visibility="hidden"))
    legPoints <- pointsGrob(x=unit(.75, "npc") - unit(2, "mm") - 
                              1:4*stringWidth("  0.00") - 0:3*unit(3, "mm"),
                            y=rep(unit(1, "npc") + unit(1, "lines"), 4),
                            pch=16, size=unit(1.5, "mm"),
                            gp=gpar(col=colors),
                            name=paste("legPoints", i, sep=""))
    grid.draw(garnishGrob(legPoints, visibility="hidden"))
    legText <- textGrob(sprintf("%0.2f", insightDF$value[subset]/100),
                        x=unit(.75, "npc") - unit(2, "mm") - 
                          0:3*stringWidth("  0.00") - 0:3*unit(3, "mm"),
                        just="right",
                        y=unit(1, "npc") + unit(1, "lines"), 
                        name=paste("legText", i, sep=""))
    grid.draw(garnishGrob(legText, visibility="hidden"))    
}
upViewport(1)
# Draw an invisible rectangle ON TOP of the panel
# to collect ALL mouse events in the panel
erect <- rectGrob(name="event-rect")
grid.draw(garnishGrob(erect, grep=TRUE,
                      visibility="hidden",
                      onmousemove=paste("highlightPoints(evt, ", 
                        ggplotScaleX(min(as.numeric(insight$Date)),
                                     min(as.numeric(insight$Date)),
                                     max(as.numeric(insight$Date))),
                        ", ",
                        ggplotScaleX(max(as.numeric(insight$Date)),
                                     min(as.numeric(insight$Date)),
                                     max(as.numeric(insight$Date))),
                        ", ",
                        nrow(insight), ")",
                        sep=""),
                      onmouseout="unhighlightPoints()",
                      "pointer-events"="all"))
grid.script(filename="highlight.js")
gridToSVG("logoplot.svg")
dev.off()
@ 

\center{\bf\color{grey}
Dynamic and Interactive Demo
}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 1}
  \end{pgfpicture}
Code for Graphics}

\begin{itemize}
\item
We create an image in R using \emph{code}.
\end{itemize}

\begin{center}
\fbox{\includegraphics[width=.8\textwidth]{tealbay.jpg}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 1}
  \end{pgfpicture}
Code for Graphics}

\begin{itemize}
\item
We create an image in R using \emph{code}.
\end{itemize}

\begin{center}
{\includegraphics[width=.8\textwidth]{tealbaycode}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 1}
  \end{pgfpicture}
Code for Graphics}

\begin{itemize}
\item
This means that ...
\begin{itemize}
\item
we have a record of what we did.
\item
we can easily repeat what we did.
\item
we can create a similar image by slightly modifying what we did.
\item
we can create lots of images easily (batch jobs).
\item
we can easily and accurately show someone else what we did
(and they can do exactly what we did, or something similar).
\item
we can generate plot content on-the-fly (e.g., time stamps).
\item
we can express complex ideas (edit all graphical objects that match a pattern).
\end{itemize}
\end{itemize}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{
\begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
    \color{black}
    \pgfcircle[fill]{\pgfpoint{0pt}{.75ex}}{1.2ex}
    \pgfbox[center,base]{\color{white}\bf 1}
  \end{pgfpicture}
Code for Graphics}

\begin{itemize}
\item
Because R is a programming language, we can encapsulate code
in functions or even packages.
\item
It also doesn't hurt that R is a \emph{statistical} programming 
language.
\begin{itemize}
\item
We can add a least-squares line to a plot.
\end{itemize}
\item
It hurts even less that \R{} is \emph{open source}.
\begin{itemize}
\item
We can easily share and build on each other's code.
\end{itemize}
\end{itemize}

\end{frame}


%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}

<<plotframe, echo=FALSE>>=
plotframe <- function(title) {
    grid.newpage()
    grid.rect(gp=gpar(col="grey50", fill="grey95"))
    grid.rect(y=1, height=unit(1, "lines"), just="top",
              gp=gpar(col=NA, fill="grey50"))
    grid.text(title,
              x=unit(1, "mm"),
              just="left",
              y=unit(1, "npc") - unit(.5, "lines"),
              gp=gpar(fontface="italic", col="white"))
    grid.text(Sys.time(), 
              x=unit(1, "npc") - unit(1, "mm"),
              just="right",
              y=unit(1, "npc") - unit(.5, "lines"),
              gp=gpar(fontface="italic", col="white"))
    grid.rect(y=0, height=unit(1, "lines"), just="bottom",
              gp=gpar(col=NA, fill="grey50"))
    grid.text("BY-NC-SA",
              x=unit(1, "npc") - unit(1, "mm"),
              just="right",
              y=unit(.5, "lines"),
              gp=gpar(fontface="italic", col="white"))
    grid.picture(cclogo,
                 x=unit(1, "npc") - 
                 stringWidth("BY-NC-SA  "),
                 y=unit(.5, "lines"), 
                 just=c("right"),
                 width=unit(1, "char"),
                 height=unit(1, "char"),
                 use.gc=FALSE, gp=gpar(col=NA, fill="white"))
    pushViewport(viewport(y=unit(1, "lines"), 
                          height=unit(1, "npc") - unit(2, "lines"),
                          just="bottom",
                          gp=gpar(cex=1)))
}
@

<<frame, fig=TRUE, include=FALSE, height=4>>=
plotframe("Title goes here")
@ 

\begin{center}
\includegraphics[width=3.5in]{rgraphics-frame}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}

<<eval=FALSE>>=
plotframe("Google Insights for Search")
ggplot( ... )
@ 

\begin{center}
{\includegraphics[width=3.5in]{rgraphics-logoplot}}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}

<<framelattice, echo=FALSE, fig=TRUE, include=FALSE, height=4>>=
plotframe("Lattice Multipanel Conditioning")
pushViewport(viewport(width=unit(1, "snpc"), gp=gpar(cex=.55)))
print(
<<latticesrc>>
, newpage=FALSE)
@ 

<<eval=FALSE>>=
plotframe("Lattice Multipanel Conditioning")
xyplot( ... )
@ 

\begin{center}
\includegraphics[width=3.5in]{rgraphics-framelattice}
\end{center}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{An Example}

<<frameoz, echo=FALSE, results=hide>>=
pdf("rgraphics-frameoz-%d.pdf", width=6, height=4, onefile=FALSE)
plot.new()
plotframe("Australian Population Density")
pushViewport(viewport(width=unit(1, "snpc"), height=unit(1, "snpc")))
library(gridBase)
par(omi=gridOMI(), new=TRUE)
<<oz>>
dev.off()
@ 

<<eval=FALSE>>=
plotframe("Australian Population Density")
oz( ... )
@ 

\begin{center}
\includegraphics[width=3.5in]{rgraphics-frameoz-2}
\end{center}

\end{frame}




%%%%%%%
%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{Summary}

\begin{itemize}
\item
  Why use R?
  \begin{itemize}
  \item
    Because if R can't already do what you want, it gives you
    lots of tools so you can do it yourself.
  \item
    Customisability:
    \begin{itemize}
    \item
      Because of the painters model.
    \item
      Because you can draw basic shapes.
    \item
      Because you have access to coordinate systems.
    \item
      Because you have access to graphical objects.
    \end{itemize}
  \item
    Extensibility:
    \begin{itemize}
    \item
      Because you can write code.
    \item
      Because you can see others' code.
    \item
      Because you have access to the same tools that others use.
    \end{itemize}
  \item
    Programmability:
    \begin{itemize}
    \item
      Because you write code to draw stuff.
    \item
      Because R is a programming language.
    \item
      Because R is a graphics language.
    \end{itemize}
  \end{itemize}
\end{itemize}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{Caveats}

\begin{itemize}
\item
Although it is possible with R to produce 3D plots and animated plots
and interactive plots, those are typically provided by connecting R
to external graphics systems.
\item
The \emph{core} R graphics system is focused on \emph{static}
\emph{2D} plots.
\end{itemize}

<<packages, echo=FALSE, fig=TRUE, include=FALSE, width=6, height=3>>=
grid.newpage()
pushViewport(viewport(layout=grid.layout(3, 3)))
pushViewport(viewport(layout.pos.row=1, layout.pos.col=2))
grid.text("grDevices")
grid.move.to(.5, .4)
popViewport()
pushViewport(viewport(layout.pos.row=2, layout.pos.col=1:2))
grid.text("grid")
grid.line.to(.5, .6, arrow=arrow(angle=10, type="closed"),
             gp=gpar(fill="black"))
popViewport()
pushViewport(viewport(layout.pos.row=1, layout.pos.col=2))
grid.move.to(.5, .4)
popViewport()
pushViewport(viewport(layout.pos.row=2, layout.pos.col=2:3))
grid.text("graphics")
grid.line.to(.5, .6, arrow=arrow(angle=10, type="closed"),
             gp=gpar(fill="black"))
popViewport()
pushViewport(viewport(layout.pos.row=2, layout.pos.col=1:2))
grid.move.to(.5, .4)
popViewport()
pushViewport(viewport(layout.pos.row=3, layout.pos.col=1))
grid.text("lattice")
grid.line.to(.5, .6, arrow=arrow(angle=10, type="closed"),
             gp=gpar(fill="black"))
popViewport()
pushViewport(viewport(layout.pos.row=2, layout.pos.col=1:2))
grid.move.to(.5, .4)
popViewport()
pushViewport(viewport(layout.pos.row=3, layout.pos.col=2))
grid.text("ggplot2")
grid.line.to(.5, .6, arrow=arrow(angle=10, type="closed"),
             gp=gpar(fill="black"))
popViewport()
@ 

\begin{center}
\includegraphics[width=2.5in]{rgraphics-packages}
\end{center}

\vspace*{-.3in}
\begin{itemize}
\item
Most of the examples have been \pkg{grid}-based graphics.
\item
(Almost) all of these examples can be achieved 
(with a little more effort) in ``traditional'' graphics.
\end{itemize}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{Further Reading}

{\small
\begin{itemize}
\item
``R Graphics''\\
\url{http://www.stat.auckland.ac.nz/~paul/RGraphics/rgraphics.html}
\item
``R Graphics, Second Edition''\\
\url{http://www.stat.auckland.ac.nz/~paul/RG2e/}
\item
``Lattice: Multivariate Data Visualization with R''\\
\url{http://lmdvr.r-forge.r-project.org/}
\item
``ggplot2: Elegant Graphics for Data Analysis''\\
\url{http://had.co.nz/ggplot2/book/}
\end{itemize}

\begin{itemize}
\item
The Graphics CRAN Task View\\
\url{http://cran.r-project.org/web/views/Graphics.html}
\item
The R Graphics Gallery\\
\url{http://addictedtor.free.fr/graphiques/}
\item
The R Graphical Manual\\
\url{http://www.oga-lab.net/RGM2/}
\end{itemize}
}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{Acknowledgements}

\begin{itemize}
\item
The Creative Commons logo is available from
\url{http://creativecommons.org/about/downloads}
under a Creative Commons Attribution license. 
\item
The GNU logo is by Aur\'{e}lio A. Heckert 
and is available from 
\url{http://commons.wikimedia.org/wiki/Image:Heckert\_GNU\_white.svg}
under a Free Art Licence.
\item
The Google Search data are from 
\url{http://www.google.com/insights/search/}
\end{itemize}

\end{frame}

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{Acknowledgements}
The following R packages were used in the production of these slides:
\begin{itemize}
\item
\pkg{ggplot2} by Hadley Wickham.
\item
\pkg{graph} (maintained) by Seth Falcon (Bioconductor).
\item
\pkg{gridBase} by Paul Murrell.
\item
\pkg{gridSVG} by Paul Murrell and Simon Potter.
\item
\pkg{grImport} by Paul Murrell and Richard Walton.
\item
\pkg{lattice} by Deepayan Sarkar.
\item
\pkg{maps} (maintained) by Ray Brownrigg.
\item
\pkg{oz} (maintained) by Kurt Hornik.
\item
\pkg{png} by Simon Urbanek.
\item
\pkg{reshape} by Haldey Wickham.
\item
\pkg{Rgraphviz} (maintained) by Kasper Hansen (Bioconductor).
\end{itemize}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% END DOCUMENT
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%
% FRAME
%%%%%%%
\begin{frame}[fragile]
\frametitle{}

\begin{itemize}
\item
\end{itemize}

\end{frame}

