Skip to content

Instantly share code, notes, and snippets.

@raffdoc
Forked from JoFrhwld/ling-plot.Rnw
Created April 15, 2012 08:35
Show Gist options
  • Save raffdoc/2390985 to your computer and use it in GitHub Desktop.
Save raffdoc/2390985 to your computer and use it in GitHub Desktop.
A knitr source file for including linguistic notation as graphical elements in ggplot2
\documentclass{beamer}
\usetheme{Singapore}
\usepackage{tipa}
%% Make the r-code small
\ifdefined\knitrout
\renewenvironment{knitrout}{\begin{footnotesize}}{\end{footnotesize}}
\else
\fi
\title{Putting IPA Characters in Plots}
\author{Josef Fruehwald}
\begin{document}
%% Don't print errors, warnings, or messages
\SweaveOpts{message=F, error=F, warning=F}
\begin{frame}[fragile]
\frametitle{Set up}
<<>>=
library(ggplot2)
library(tikzDevice)
@
\end{frame}
\begin{frame}[fragile]
Just put in any special \LaTeX package you want to use here.
<<tidy=F>>=
options(tikzLatexPackages = c(getOption("tikzLatexPackages"),
"\\usepackage{tipa}",
"\\usepackage{qtree}"))
@
\end{frame}
\begin{frame}[fragile]
\frametitle{Fake up some data}
<<tidy=F>>=
levels(mpg$drv) <- c("\\textipa{D}",
"\\textipa{C}",
"\\textipa{P}")
@
\end{frame}
\begin{frame}[fragile]
\frametitle{Profit}
<<dev="tikz", fig.width=8, fig.height=5, out.width="0.9\\textwidth", fig.align="center", tidy = F>>=
ggplot(mpg, aes(displ, hwy, label = drv, color = drv)) +
geom_text() +
stat_smooth()+
xlab("\\textipa{IPA!}")
@
\end{frame}
\begin{frame}[fragile]
\frametitle{Profit}
<<dev="tikz", fig.width=8, fig.height=5, out.width="0.7\\textwidth", fig.align="center", tidy = F>>=
ggplot(mpg, aes(displ, hwy, label = drv, color = drv)) +
geom_text() +
stat_smooth()+
xlab("\\textipa{IPA!}")+
annotate(x=5.5, y = 40, geom = "text",
label = "\\Tree [.S \\qroof{I}.NP \\qroof{just blew my own mind}.VP ]")
@
\end{frame}
\begin{frame}[fragile]
\frametitle{Fake up some data}
<<tidy=F>>=
mpg$tree <- "{\\footnotesize \\Tree [.S NP VP ]}"
@
\end{frame}
\begin{frame}[fragile]
\frametitle{Profit}
<<dev="tikz", fig.width=8, fig.height=5, out.width="0.7\\textwidth", fig.align="center", tidy = F>>=
ggplot(mpg, aes(displ, hwy, label = tree))+
geom_text() +
stat_smooth()+
xlab("TREES")
@
\end{frame}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment