Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R, ggplot2, introducing the elements of a graph sequentially during a keynote presentation

Tags:

r

ggplot2

I use ggplot2 to plot my graphs. I want to use the graphs to create a keynote presentation.

During my presentation, I want to introduce different elements of the plot sequentially. First, the points corresponding to the condition A, then the points corresponding to condition B and then some curves for example.

I thought that maybe I could create the whole plot and export it in a way that I could manipulate single elements in keynote (like deleting the points of one condition). Thanks to people from stackoverflow, I was able to do that: R, export a file to keynote

But I found that it is very difficult to select individual elements in keynote. So, I wonder which is there is some more efficient way.

like image 300
danilinares Avatar asked Oct 10 '11 02:10

danilinares


1 Answers

If you're willing to use some different tools, this is very doable with Sweave and the LaTeX document class beamer for the slides:

\documentclass{beamer}
\title{Sequential Graphs}
\begin{document}

\frame{\titlepage}

\frame{
Here's a graph:
<<echo = FALSE,fig = TRUE>>=
library(ggplot2)
d1 <- data.frame(x = 1:20, y = runif(20),grp = rep(letters[1:2],each = 10))
p <- ggplot(data = d1, aes(x = x, y = y)) + geom_point()
print(p)
@
}

\frame{
Here's the next graph:
<<echo = FALSE,fig = TRUE>>=
p <- p +geom_line(aes(group = 1))
print(p)
@
}

\frame{
Here's the last graph:
<<echo = FALSE,fig = TRUE>>=
p <- p +geom_point(aes(colour = grp))
print(p)
@
}
\end{document}

I've used ggplot here since it has a convenient syntax for adding elements to a graph, but this should work with any other graphics method in R, I'd think.

like image 116
joran Avatar answered Oct 16 '22 23:10

joran