Sparklines in ggplot2
<p>Tufte Sparklines (as illustrated in his <em>Beautiful Evidence</em>) have been replicated in <strong>base graphics</strong> as part of <a href="https://cran.r-project.org/web/packages/YaleToolkit/index.html" rel="noreferrer">YaleToolkit</a> and further perfected as a result of <a href="https://stackoverflow.com/questions/8337980/r-yaletoolkit-how-to-change-the-font-size-of-tick-labels-on-the-sparklines/8345519#8345519">this question</a>. Sparklines have also been done in <strong>lattice</strong> as a part of my small side project <a href="http://www.motioninsocial.com/tufte/#sparklines" rel="noreferrer"><em>Tufte in R</em></a> (self-promotion not intended). My goal now is to replicate Tufte sparklines in <strong>ggplot2</strong>. There are some scripts <a href="https://gist.github.com/bds/759838" rel="noreferrer">floating around on Gist</a> and also as a reply to <a href="https://stackoverflow.com/questions/2331070/r-ggplot2-sparklines-from-dynamic-variables-based-on-query-results">this question on SO</a>, but none of those give a solid base for making replicable sets of sparklines. </p>

<p>Now, I would like those multiple sparklines to look like this (it was done in base graphics and the <a href="http://www.motioninsocial.com/tufte/#sparklines" rel="noreferrer">code is available here</a>) - dots stand for maximum/minimum values, number on right end is a final value in specific time series and grey band shows a rough quantiles range:</p>

<p><a href="https://i.stack.imgur.com/h6NcG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/h6NcG.png" alt="enter image description here"></a></p>

<p>I'm not far away but I'm stuck with the assignment of minimal/maximum values and labels:</p>

<pre><code>library(ggplot2)
library(ggthemes)
library(dplyr)
library(reshape)
library(RCurl)
dd &lt;- read.csv(text =
  getURL("https://gist.githubusercontent.com/GeekOnAcid/da022affd36310c96cd4/raw/9c2ac2b033979fcf14a8d9b2e3e390a4bcc6f0e3/us_nr_of_crimes_1960_2014.csv"))
d &lt;- melt(dd, id="Year")
names(d) &lt;- c("Year","Crime.Type","Crime.Rate")
dd &lt;- group_by(d, Crime.Type) %&gt;% 
  mutate(color = (min(Crime.Rate) == Crime.Rate | max(Crime.Rate) == Crime.Rate))
ggplot(dd, aes(x=Year, y=Crime.Rate)) + 
  facet_grid(Crime.Type ~ ., scales = "free_y") + 
  geom_line(size=0.3) + geom_point(aes(color = color)) + 
  scale_color_manual(values = c(NA, "red"), guide=F) +
  theme_tufte(base_size = 15) + 
  theme(axis.title=element_blank(), 
        axis.text.y = element_blank(), axis.ticks = element_blank()) +
  theme(strip.text.y = element_text(angle = 0, vjust=0.2, hjust=0)) 
</code></pre>

<p><a href="https://i.stack.imgur.com/gDZ2w.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gDZ2w.png" alt="enter image description here"></a></p>