Skip to content

Commit

Permalink
Done. 🏁
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik committed Apr 8, 2013
1 parent 348cb07 commit c6fd32c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
35 changes: 16 additions & 19 deletions ggplot.Rnw
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
\setcounter{secnumdepth}{-1}
\usetheme{Amsterdam}
% --------------------------------------------------------------
% Setting up some knitr options
<<setup, include=FALSE>>=
opts_chunk$set(cache=TRUE, message=FALSE)
# smaller font size for chunks
opts_chunk$set(size = 'footnotesize')
@

% --------------------------------------------------------------
% Setting up some knitr options
<<echo=FALSE>>=
options(width = 60)
@

Expand All @@ -30,7 +26,7 @@ options(width = 60)
\begin{frame}[fragile]
\frametitle{Some housekeeping}
Install some packages
<<some_data22, tidy=FALSE, echo=TRUE, eval=FALSE>>=
<<installation, tidy=FALSE, echo=TRUE, eval=FALSE>>=
install.packages("ggplot2", dependencies = TRUE)
@
\end{frame}
Expand Down Expand Up @@ -152,7 +148,7 @@ myplot + geom_point()
\begin{frame}[fragile]
\frametitle{Increase the size of points}
<<first_plot_size , fig.width=6, fig.height=4, out.width='.75\\linewidth', fig.show='hold', tidy=FALSE>>=
ggplot(data = iris, aes(x= Sepal.Length, y= Sepal.Width)) +
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point(size = 3)
@
\end{frame}
Expand Down Expand Up @@ -291,7 +287,7 @@ geom_bar(stat = "identity")
% --------------------------------------------------------------
\begin{frame}[fragile]
<<bartwo , fig.width=6, fig.height=4, out.width='.75\\linewidth', fig.show='hold', tidy=FALSE>>=
df <- melt(iris, id.vars="Species")
df <- melt(iris, id.vars = "Species")
ggplot(df, aes(Species, value, fill = variable)) +
geom_bar(stat = "identity")
@
Expand Down Expand Up @@ -413,7 +409,7 @@ display.brewer.all()
\begin{frame}[fragile]
\frametitle{Using a color brewer palette}
<<barcolors, fig.width=6, fig.height=4, out.width='.75\\linewidth', fig.show='hold', tidy=FALSE>>=
df <- melt(iris, id.vars="Species")
df <- melt(iris, id.vars = "Species")
ggplot(df, aes(Species, value, fill = variable)) +
geom_bar(stat = "identity", position = "dodge") +
scale_fill_brewer(palette = "Set1")
Expand Down Expand Up @@ -592,8 +588,8 @@ scale_linetype(), scale_shape_manual()
library(MASS)
ggplot(birthwt, aes(factor(race), bwt)) +
geom_boxplot(width = .2) +
scale_y_continuous(labels = (paste0(1:4, " K")),
breaks=seq(1000, 4000, by = 1000))
scale_y_continuous(labels = (paste0(1:4, " Kg")),
breaks = seq(1000, 4000, by = 1000))
@
\end{frame}
Expand All @@ -608,8 +604,8 @@ geom_point(size = 4, shape = 16) +
facet_grid(. ~Species)
# Now add a scale
dd +
scale_y_continuous(breaks=seq(2, 8,by = 1),
labels=paste0(2:8, " cm"))
scale_y_continuous(breaks = seq(2, 8, by = 1),
labels = paste0(2:8, " cm"))
@
\end{frame}
Expand All @@ -629,18 +625,19 @@ ggsave('~/path/to/figure/filename.png')
@
\item If your plot is assigned to an object
<<pub1, eval = FALSE, out.width='.75\\linewidth'>>=
ggsave(plot1, '~/path/to/figure/filename.png')
ggsave(plot1, file = "~/path/to/figure/filename.png")
@
\item Specify a size
<<pub2, eval = FALSE, out.width='.75\\linewidth'>>=
ggsave("/path/to/figure/filename.png", width = 6, height =4)
<<pub2, eval = FALSE, out.width='.75\\linewidth', tidy = FALSE>>=
ggsave(file = "/path/to/figure/filename.png", width = 6,
height =4)
@
\item or any format (pdf, png, eps, svg, jpg)
<<pub3, eval = FALSE, out.width=".75\\linesewidth">>=
ggsave("/path/to/figure/filename.eps")
ggsave("/path/to/figure/filename.jpg")
ggsave("/path/to/figure/filename.pdf")
ggsave(file = "/path/to/figure/filename.eps")
ggsave(file = "/path/to/figure/filename.jpg")
ggsave(file = "/path/to/figure/filename.pdf")
@
\end{itemize}
\end{frame}
Expand Down
Binary file modified ggplot.pdf
Binary file not shown.
29 changes: 13 additions & 16 deletions ggplot.tex
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@
\usepackage{url}
\setcounter{secnumdepth}{-1}
\usetheme{Amsterdam}
% --------------------------------------------------------------



% --------------------------------------------------------------
% Setting up some knitr options

Expand Down Expand Up @@ -236,7 +232,7 @@ \section*{Assembling your first ggplot}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlfunctioncall{ggplot}(data = iris, \hlfunctioncall{aes}(x= Sepal.Length, y= Sepal.Width)) +
\hlfunctioncall{ggplot}(data = iris, \hlfunctioncall{aes}(x = Sepal.Length, y = Sepal.Width)) +
\hlfunctioncall{geom_point}(size = 3)
\end{alltt}
\end{kframe}
Expand Down Expand Up @@ -443,7 +439,7 @@ \section*{Bar plots}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
df <- \hlfunctioncall{melt}(iris, id.vars=\hlstring{"Species"})
df <- \hlfunctioncall{melt}(iris, id.vars = \hlstring{"Species"})
\hlfunctioncall{ggplot}(df, \hlfunctioncall{aes}(Species, value, fill = variable)) +
\hlfunctioncall{geom_bar}(stat = \hlstring{"identity"})
\end{alltt}
Expand Down Expand Up @@ -629,7 +625,7 @@ \section*{Mapping Variables to colors}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
df <- \hlfunctioncall{melt}(iris, id.vars=\hlstring{"Species"})
df <- \hlfunctioncall{melt}(iris, id.vars = \hlstring{"Species"})
\hlfunctioncall{ggplot}(df, \hlfunctioncall{aes}(Species, value, fill = variable)) +
\hlfunctioncall{geom_bar}(stat = \hlstring{"identity"}, position = \hlstring{"dodge"}) +
\hlfunctioncall{scale_fill_brewer}(palette = \hlstring{"Set1"})
Expand Down Expand Up @@ -879,8 +875,8 @@ \section*{Scales}
\hlfunctioncall{library}(MASS)
\hlfunctioncall{ggplot}(birthwt, \hlfunctioncall{aes}(\hlfunctioncall{factor}(race), bwt)) +
\hlfunctioncall{geom_boxplot}(width = .2) +
\hlfunctioncall{scale_y_continuous}(labels = (\hlfunctioncall{paste0}(1:4, \hlstring{" K"})),
breaks=\hlfunctioncall{seq}(1000, 4000, by = 1000))
\hlfunctioncall{scale_y_continuous}(labels = (\hlfunctioncall{paste0}(1:4, \hlstring{" Kg"})),
breaks = \hlfunctioncall{seq}(1000, 4000, by = 1000))
\end{alltt}
\end{kframe}
\includegraphics[width=.75\linewidth]{figure/boxplots3_}
Expand All @@ -902,8 +898,8 @@ \section*{Scales}
\hlfunctioncall{facet_grid}(. ~Species)
\hlcomment{# Now add a scale}
dd +
\hlfunctioncall{scale_y_continuous}(breaks=\hlfunctioncall{seq}(2, 8,by = 1),
labels=\hlfunctioncall{paste0}(2:8, \hlstring{" cm"}))
\hlfunctioncall{scale_y_continuous}(breaks = \hlfunctioncall{seq}(2, 8, by = 1),
labels = \hlfunctioncall{paste0}(2:8, \hlstring{" cm"}))
\end{alltt}
\end{kframe}
\end{knitrout}
Expand Down Expand Up @@ -933,7 +929,7 @@ \section*{Publication quality figures}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlfunctioncall{ggsave}(plot1, \hlstring{"~/path/to/figure/filename.png"})
\hlfunctioncall{ggsave}(plot1, file = \hlstring{"~/path/to/figure/filename.png"})
\end{alltt}
\end{kframe}
\end{knitrout}
Expand All @@ -943,7 +939,8 @@ \section*{Publication quality figures}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlfunctioncall{ggsave}(\hlstring{"/path/to/figure/filename.png"}, width = 6, height = 4)
\hlfunctioncall{ggsave}(file = \hlstring{"/path/to/figure/filename.png"}, width = 6,
height =4)
\end{alltt}
\end{kframe}
\end{knitrout}
Expand All @@ -952,9 +949,9 @@ \section*{Publication quality figures}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlfunctioncall{ggsave}(\hlstring{"/path/to/figure/filename.eps"})
\hlfunctioncall{ggsave}(\hlstring{"/path/to/figure/filename.jpg"})
\hlfunctioncall{ggsave}(\hlstring{"/path/to/figure/filename.pdf"})
\hlfunctioncall{ggsave}(file = \hlstring{"/path/to/figure/filename.eps"})
\hlfunctioncall{ggsave}(file = \hlstring{"/path/to/figure/filename.jpg"})
\hlfunctioncall{ggsave}(file = \hlstring{"/path/to/figure/filename.pdf"})
\end{alltt}
\end{kframe}
\end{knitrout}
Expand Down

0 comments on commit c6fd32c

Please sign in to comment.