<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/ggplot2-how-geoms-aesthetics-%e2%89%88-whipped-cream/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://trinkerrstuff.wordpress.com/2018/03/21/ggplot2-how-geoms-aesthetics-%E2%89%88-whipped-cream/"> R – TRinker's R Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>In this post I have a few goals:</p>
<p>1. Become (re-)familiar with available geoms<br>
2. Become (re-)familiar with aesthetic mappings in geoms (stroke who knew?)<br>
3. Answer these questions:</p>
<ul>
<li>How often do various geoms appear and how often do they have required aesthetics?</li>
<li>How often do various aesthetics appear and how often are they required?</li>
<li>What geoms are most similar based on mappings?</li>
</ul>
<h2>The Back Story</h2>
<p>Two weeks go I made whipped cream for the first time. In a tweet I lamented not having tried making it earlier in my life:</p>
<p><img data-orig-file="https://trinkerrstuff.files.wordpress.com/2018/03/capture6.png?w=356&amp;h=162&amp;fit=356%2C162&amp;resize=356%2C162" data-orig-size="598,272" data-medium-file="https://trinkerrstuff.files.wordpress.com/2018/03/capture6.png?w=356&amp;h=162&amp;fit=356%2C162&amp;resize=356%2C162?w=300" data-attachment-id="2275" data-image-meta="{" data-image-description="" src="https://trinkerrstuff.files.wordpress.com/2018/03/capture6.png?w=356&h=162&fit=356%2C162&resize=356%2C162" data-permalink="https://trinkerrstuff.wordpress.com/2018/03/21/ggplot2-how-geoms-aesthetics-%e2%89%88-whipped-cream/capture-7/" data-large-file="https://trinkerrstuff.files.wordpress.com/2018/03/capture6.png?w=356&amp;h=162&amp;fit=356%2C162&amp;resize=356%2C162?w=598" alt="Capture" data-image-title="Capture" sizes="(max-width: 356px) 100vw, 356px" width="356" data-comments-opened="1" class="wp-image-2275" data-recalc-dims="1" height="162"></p>
<p>This was an error that resulted in missing out because of a lack of confidence. Now the opposite tale. Missing out because of false confidence. I know ggplot2…there’s nothing new to learn. Recently I realized it’s been too long since I’ve re-read the documentation. I’m betting my time making this blog post that there’s a few more like me.</p>
<p>I’m teaching an upcoming analysis course.  To prepare I’m reading and rereading many important texts including <a rel="nofollow" href="http://r4ds.had.co.nz/" target="_blank">R for Data Science</a>.  In my close read I noticed that some ggplot2 functions have a stroke aesthetic.</p>
<p><img alt="Image result for puzzled meme" src="https://i0.wp.com/www.relatably.com/m/img/puzzled-memes/b805e4fd98e530149b466b9ec501f39d.jpg"></p>
<p>Didn’t know that…I figure I needed to spend a bit more time with the documentation and really get to know geoms and aesthetics that I may have overlooked.  </p>
<h2>What’s an aesthetic Anyways?</h2>
<p>ggplot2’s author, Hadley, states:</p>
<blockquote>
<p>In brief, the grammar tells us that a statistical graphic is a mapping from data to aesthetic attributes (colour, shape, size) of geometric objects (points, lines, bars)….aesthetics…are the properties that can be perceived on the graphic. Each aesthetic can be mapped to a variable, or set to a constant value.  pp. 4; 176
</p>
</blockquote>
<p>So without aesthetics, geoms can’t represent data.</p>
<h2>Getting the Geoms and Their Aesthetics</h2>
<p>Before getting started note that wordpress.com destroys code. To get the undestroyed version of code from this blog use this gist: <a rel="nofollow" href="https://gist.github.com/trinker/a03c24a7fe9603d3091f183ffe4781ab" target="_blank">https://gist.github.com/trinker/a03c24a7fe9603d3091f183ffe4781ab</a></p>
<p>I wasn’t sure how I was going to accomplish this task but a little digging showed that it was pretty easy.  First I used <a rel="nofollow" href="https://github.com/Dasonk" target="_blank">Dason Kurkiewicz</a>  &amp; I’s <a rel="nofollow" href="https://github.com/trinker/pacman" target="_blank">pacman</a> package to get all the geoms from ggplot2.  This is where I first hit a road block.  How do I get the aesthetics for a geom?  I recalled that the documentation tells you the aesthetics for each geom.  I noticed that in <a rel="nofollow" href="https://github.com/tidyverse/ggplot2/blob/master/R/geom-bar.r" target="_blank">the roxygen2 markup</a> the following line that creates the aesthetics reference in the documentation:</p>
<pre>@eval rd_aesthetics(&quot;geom&quot;, &quot;bar&quot;)</pre>
<p>That allowed me to follow the bread crumbs to make the following code to grab the aesthetics per geom and a flag for when an aesthetic is required:</p>
<pre>
if (!require(&quot;pacman&quot;)) install.packages(&quot;pacman&quot;)
pacman::p_load(pacman, ggplot2, dplyr, textshape, numform, tidyr, lsa, viridis)

## get the geoms
geoms &lt;- gsub('^geom_', '', grep('^geom_', p_funs(ggplot2), value = TRUE))

## function to grab the aesthetics
get_aesthetics &lt;- function(name, type){

    obj &lt;- switch(type, geom = ggplot2:::find_subclass(&quot;Geom&quot;, name, globalenv()), 
        stat = ggplot2:::find_subclass(&quot;Stat&quot;, name, globalenv()))
    aes &lt;- ggplot2:::rd_aesthetics_item(obj)

    req &lt;- obj$required_aes

    data_frame(
        aesthetic = union(req, sort(obj$aesthetics())),
        required = aesthetic %in% req,

    )
}

## loop through and grab the aesthetics per geom
aesthetics_list &lt;- lapply(geoms, function(name){

    type &lt;- 'geom'
 
    name &lt;- switch(name,
        jitter = 'point',
        freqpoly = 'line',
        histogram = 'bar',
        name
    )

    out &lt;- try(get_aesthetics(name, 'geom'), silent = TRUE)

    if (inherits(out, 'try-error')) out %
    setNames(geoms)

## convert the list of data.frames to one tidy data.frame
aesthetics %
    tidy_list('geom') %>%
    tbl_df()

aesthetics
</pre>
<pre>
   geom   aesthetic required
             
 1 abline slope     TRUE    
 2 abline intercept TRUE    
 3 abline alpha     FALSE   
 4 abline colour    FALSE   
 5 abline group     FALSE   
 6 abline linetype  FALSE   
 7 abline size      FALSE   
 8 area   x         TRUE    
 9 area   y         TRUE    
10 area   alpha     FALSE   
# ... with 341 more rows
</pre>
<h2>Geoms: Getting Acquainted</h2>
<p>First I wanted to get to know geoms again. There are currently 44 of them.</p>
<pre>
length(unique(aesthetics$geom))

## 44
</pre>
<p>This bar plot details the geoms and how many aesthetics are optional/required.</p>
<pre>
geom_ord %
    count(geom) %>%
    arrange(n) %>%
    pull(geom)


aesthetics %>%
    mutate(geom = factor(geom, levels = geom_ord)) %>%
    ggplot(aes(geom, fill = required)) +
        geom_bar() +
        coord_flip() +
        scale_y_continuous(expand = c(0, 0), limits = c(0, 15)) +
        scale_fill_manual(name = 'Required', values = c('gray88', '#1C86EE'), labels = f_response) +
        theme_minimal() +
        theme(
            panel.grid.major.y = element_blank(),
            axis.text = element_text(color = 'grey55', size = 10),
            legend.key.size = unit(.35, 'cm'),
            legend.title = element_text(color = 'grey30', size = 10),
            legend.position = c(.76, .1),
            axis.title = element_text(color = 'gray55')
        ) +
        labs(
            x = 'Geom',
            y = 'Count',
            title = 'Count of Geom Aesthetics',
            subtitle = 'Distribution of geom aesthetic count filled by requirement flag.'

        ) 
</pre>
<p><img data-orig-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_count.png?w=80%25" data-orig-size="1994,1992" data-medium-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_count.png?w=80%25?w=300" data-attachment-id="2264" data-image-meta="{" data-image-description="" src="https://trinkerrstuff.files.wordpress.com/2018/03/geom_count.png?w=80%25" data-permalink="https://trinkerrstuff.wordpress.com/2018/03/21/ggplot2-how-geoms-aesthetics-%e2%89%88-whipped-cream/geom_count/" data-large-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_count.png?w=80%25?w=640" alt="geom_count" data-image-title="geom_count" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-2264" data-recalc-dims="1"></p>
<p>Some interesting things come out. Most geoms have 2ish required aesthetics. The boxplot geom has the most required and unrequired aesthetics. Sensibly, a blank geom requires no aesthetics. I wanted to see what all of these aesthetics were for the boxplot. Some quick dplyr-ing has us there in no time.</p>
<pre>
aesthetics %>%
    filter(geom == 'boxplot')
</pre>
<pre>
   geom    aesthetic required
              
 1 boxplot x         TRUE    
 2 boxplot lower     TRUE    
 3 boxplot upper     TRUE    
 4 boxplot middle    TRUE    
 5 boxplot ymin      TRUE    
 6 boxplot ymax      TRUE    
 7 boxplot alpha     FALSE   
 8 boxplot colour    FALSE   
 9 boxplot fill      FALSE   
10 boxplot group     FALSE   
11 boxplot linetype  FALSE   
12 boxplot shape     FALSE   
13 boxplot size      FALSE   
14 boxplot weight    FALSE   
</pre>
<p>Seems that <code>x</code> is the only aesthetic that is truly required. The other “required” ones are computed if you just supply <code>x</code>.</p>
<h2>Aesthetics: May I join You?</h2>
<p>Now time to get to know aesthetics. Are there others like <code>stroke</code> that I’ve overlooked? There are 36 aesthetics currently. I see right away that there is a <code>weight</code> aesthetic I’ve never seen before.</p>
<pre>
length(unique(aesthetics$aesthetic))

## 36
</pre>
<pre>
aes_ord %
    count(aesthetic) %>%
    arrange(n) %>%
    pull(aesthetic)

aesthetics %>%
    mutate(aesthetic = factor(aesthetic, levels = aes_ord)) %>%
    ggplot(aes(aesthetic, fill = required)) +
        geom_bar() +
        scale_y_continuous(expand = c(0, 0), limits = c(0, 45), breaks = seq(0, 45, by = 5)) +
        scale_fill_manual(name = 'Required', values = c('gray88', '#1C86EE'), labels = f_response) +
        theme_minimal() +
        theme(
            panel.grid.major.y = element_blank(),
            panel.grid.minor = element_blank(),
            axis.text = element_text(color = 'grey55', size = 10),
            legend.key.size = unit(.35, 'cm'),
            legend.title = element_text(color = 'grey30', size = 10),
            legend.position = c(.83, .1),
            axis.title = element_text(color = 'gray55')
        ) +
        labs(
            x = 'Aesthetic',
            y = 'Count',
            title = 'Count of Aesthetics',
            subtitle = 'Distribution of aesthetics filled by requirement flag.'
        ) +
        coord_flip()
</pre>
<p><img data-orig-file="https://trinkerrstuff.files.wordpress.com/2018/03/aes_count.png?w=90%25" data-orig-size="1994,1992" data-medium-file="https://trinkerrstuff.files.wordpress.com/2018/03/aes_count.png?w=90%25?w=300" data-attachment-id="2265" data-image-meta="{" data-image-description="" src="https://trinkerrstuff.files.wordpress.com/2018/03/aes_count.png?w=90%25" data-permalink="https://trinkerrstuff.wordpress.com/2018/03/21/ggplot2-how-geoms-aesthetics-%e2%89%88-whipped-cream/aes_count/" data-large-file="https://trinkerrstuff.files.wordpress.com/2018/03/aes_count.png?w=90%25?w=640" alt="aes_count" data-image-title="aes_count" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-2265" data-recalc-dims="1"></p>
<p>It seems from this plot that almost every geom requires an x/y position aesthetic. That makes sense. What doesn’t make sense are cases besides <code>geom_blank</code> that don’t require x/y.</p>
<pre>
aesthetics %>%
    filter(aesthetic %in% c('x', 'y') &amp; !required)
</pre>
<pre>
  geom  aesthetic required
           
1 count y         FALSE   
2 qq    x         FALSE   
3 qq    y         FALSE   
4 rug   x         FALSE   
5 rug   y         FALSE 
</pre>
<p>This dplyr summarize/filter shows where an x/y are possible aesthetics but not required. Sensible. But are there some geoms that x/y aren’t even in their mapping?</p>
<pre>
aesthetics %>%
    group_by(geom) %>% 
    summarize(
        has_x = 'x' %in% aesthetic, 
        has_y = 'y' %in% aesthetic 
    ) %>%
    filter(!has_x | ! has_y) %>%
    arrange(has_x)
</pre>
<pre>
   geom      has_x has_y
         
 1 abline    FALSE FALSE
 2 blank     FALSE FALSE
 3 hline     FALSE FALSE
 4 map       FALSE FALSE
 5 rect      FALSE FALSE
 6 vline     FALSE FALSE
 7 boxplot   TRUE  FALSE
 8 errorbar  TRUE  FALSE
 9 linerange TRUE  FALSE
10 ribbon    TRUE  FALSE
</pre>
<p>Dig into the documentation if you want to make sense of why these geoms don’t require x/y positions.</p>
<h2>Geoms &amp; Aesthetics Intersect</h2>
<p>OK so we’ve explored variability in geoms and aesthetics a bit…let’s see how they covary. The heatmap below provides an understanding of what geoms utilize what aesthetics and if they are required. <code>NA</code> means that the aesthetic is not a part of the geom’s mapping.</p>
<pre>
boolean %
    count(geom, aesthetic) %>%
    spread(aesthetic, n, fill = 0)


boolean %>%
    gather(aesthetic, value, -geom) %>%
    left_join(aesthetics, by  = c('geom', 'aesthetic')) %>%
    mutate(
        aesthetic = factor(aesthetic, levels = rev(aes_ord)),
        geom = factor(geom, levels = rev(geom_ord))        
    ) %>%
    ggplot(aes(y = aesthetic, x = geom, fill = required)) +
         geom_tile(color = 'grey95') +
         scale_fill_manual(name = 'Required', values = c('gray88', '#1C86EE'), labels = f_response) +
         theme_minimal() +
         theme(
             axis.ticks = element_blank(),
             axis.text.y = element_text(size = 8, margin = margin(r = -3)),
             axis.text.x = element_text(size = 8, hjust = 1, vjust = 1, 
                 angle = 45, margin = margin(t = -3)),   
             legend.key.size = unit(.35, 'cm'),
             legend.title = element_text(color = 'grey30', size = 10),
             panel.grid = element_blank(),
             axis.title = element_text(color = 'gray55')                
         ) +
         labs(
             title = 'Geom &amp; Aesthetic Co-occurrence',
             subtitle = NULL, 
             y = 'Aesthetic',
             x = 'Geom'
         )
</pre>
<p>Here we can see that <code>weight</code> aesthetic again. Hmmm, boxplot has it and other, mostly univariate functions as well. The documentation is a bit sparse on it. Hadley says: <a rel="nofollow" href="https://github.com/tidyverse/ggplot2/issues/1893" target="_blank">https://github.com/tidyverse/ggplot2/issues/1893</a></p>
<p><img data-orig-file="https://trinkerrstuff.files.wordpress.com/2018/03/aes_geom_count.png?w=456" data-orig-size="2815,1992" data-medium-file="https://trinkerrstuff.files.wordpress.com/2018/03/aes_geom_count.png?w=456?w=300" data-attachment-id="2268" data-image-meta="{" data-image-description="" src="https://trinkerrstuff.files.wordpress.com/2018/03/aes_geom_count.png?w=456" data-permalink="https://trinkerrstuff.wordpress.com/2018/03/21/ggplot2-how-geoms-aesthetics-%e2%89%88-whipped-cream/aes_geom_count/" data-large-file="https://trinkerrstuff.files.wordpress.com/2018/03/aes_geom_count.png?w=456?w=640" alt="aes_geom_count" data-image-title="aes_geom_count" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-2268" data-recalc-dims="1"></p>
<p>Also there are two geoms that are just now catching my eye…<code>geom_count</code> &amp; <code>geom_spoke</code>. I’ll come back to them later.</p>
<p>Also, there are a few aesthetics like <code>height</code> and <code> intercept</code> that are one time use only aesthetics. Also, the bottom 10 aesthetics are used, by far, the most frequently. For beginners, these are the ones that will really pay to learn quickly.</p>
<h2>Geom Similarity</h2>
<p>I thought it my be fun to use the geoms aesthetics to see if we could cluster aesthetically similar geoms closer together. The heatmap below uses cosine similarity and heirarchical clustering to reorder the matrix that will allow for like geoms to be found closer to one another (note that today I learned from “R for Data Science” about the seriation package [https://cran.r-project.org/web/packages/seriation/index.html] that may make this matrix reordering task much easier).</p>
<pre>
boolean %>%
    column_to_rownames() %>% 
    as.matrix() %>%
    t() %>%
    cosine() %>%
    cluster_matrix() %>%
    tidy_matrix('geom', 'geom2') %>%
    mutate(
        geom = factor(geom, levels = unique(geom)),
        geom2 = factor(geom2, levels = unique(geom2))        
    ) %>%
    group_by(geom) %>%
    ggplot(aes(geom, geom2, fill = value)) +
         geom_tile() +
         scale_fill_viridis(name = bquote(cos(theta))) +
         theme(
             axis.text.y = element_text(size = 8)   ,
             axis.text.x = element_text(size = 8, hjust = 1, vjust = 1, angle = 45),   
             legend.position = 'bottom',
             legend.key.height = grid::unit(.2, 'cm'),
             legend.key.width = grid::unit(.7, 'cm'),
             axis.title = element_text(color = 'gray55')               
         ) +
         labs(
             title = &quot;ggplot2 Geom Cosine Similarity&quot;,
             subtitle = 'Geoms with similar aesthetics are clustered together along the diagonal.',
             x = 'Geom',
             y = 'Geom'
         )
</pre>
<p><img data-orig-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_sim.png?w=456" data-orig-size="2172,2197" data-medium-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_sim.png?w=456?w=297" data-attachment-id="2269" data-image-meta="{" data-image-description="" src="https://trinkerrstuff.files.wordpress.com/2018/03/geom_sim.png?w=456" data-permalink="https://trinkerrstuff.wordpress.com/2018/03/21/ggplot2-how-geoms-aesthetics-%e2%89%88-whipped-cream/geom_sim/" data-large-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_sim.png?w=456?w=640" alt="geom_sim" data-image-title="geom_sim" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-2269" data-recalc-dims="1"></p>
<p>Looking at the bright square clusters along the diagonal is a good starting place for understanding which geoms tend to aesthetically cluster together. Generally, this ordering seems pretty reasonable.</p>
<h2>Aesthetic Similarity</h2>
<p>I performed the same analysis of aesthetics, asking which ones tended to be used within the same geoms. </p>
<pre>
boolean %>%
    column_to_rownames() %>% 
    as.matrix() %>%
    cosine() %>% 
    {x &lt;- .; diag(x) %
    cluster_matrix() %>%
    tidy_matrix('aesthetic', 'aesthetic2') %>%
    mutate(
        aesthetic = factor(aesthetic, levels = unique(aesthetic)),
        aesthetic2 = factor(aesthetic2, levels = unique(aesthetic2))        
    ) %>%
    group_by(aesthetic) %>%
    ggplot(aes(aesthetic, aesthetic2, fill = value)) +
         geom_tile() +
         scale_fill_viridis(name = bquote(cos(theta))) +
         theme(
             axis.text.y = element_text(size = 8)   ,
             axis.text.x = element_text(size = 8, hjust = 1, vjust = 1, angle = 45),   
             legend.position = 'bottom',
             legend.key.height = grid::unit(.2, 'cm'),
             legend.key.width = grid::unit(.7, 'cm'),
             axis.title = element_text(color = 'gray55')                
         ) +
         labs(
             title = &quot;ggplot2 Aesthetics Cosine Similarity&quot;,
             subtitle = f_wrap(c(
                 'Aesthetics that tend to be used together within the same geoms are clustered together along the diagonal.'
                 ), width = 95, collapse = TRUE
             ), 
             x = 'Aesthetic',
             y = 'Aesthetic'
         )
</pre>
<p><img data-orig-file="https://trinkerrstuff.files.wordpress.com/2018/03/aes_sim.png?w=456" data-orig-size="2172,2197" data-medium-file="https://trinkerrstuff.files.wordpress.com/2018/03/aes_sim.png?w=456?w=297" data-attachment-id="2270" data-image-meta="{" data-image-description="" src="https://trinkerrstuff.files.wordpress.com/2018/03/aes_sim.png?w=456" data-permalink="https://trinkerrstuff.wordpress.com/2018/03/21/ggplot2-how-geoms-aesthetics-%e2%89%88-whipped-cream/aes_sim/" data-large-file="https://trinkerrstuff.files.wordpress.com/2018/03/aes_sim.png?w=456?w=640" alt="aes_sim" data-image-title="aes_sim" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-2270" data-recalc-dims="1"></p>
<p>The result is pretty sensible. The lower left corner has the largest cluster which seems to be related to text based geoms. The next cluster up and to the right one, has group, size, x, y, etc. This seems to be the most common set of typically geometric aesthetics. The upper, lower, middle cluster is specific to the boxplot summary stat. Stroke and shape as a cluster are related to geoms that are point based.</p>
<h2>Geom Similarity: Required Aesthetics</h2>
<p>The last clustering activity I wanted was to reduce the seahetics to jsut required (as we might assume these are the truest attributes of a geom) and see which geoms cluster from that analysis.</p>
<pre>
boolean2 %
    filter(required) %>%
    count(geom, aesthetic) %>%
    spread(aesthetic, n, fill = 0)

	
boolean2 %>%
    column_to_rownames() %>% 
    as.matrix() %>%
    t() %>%
    cosine() %>%
    cluster_matrix() %>%

    tidy_matrix('geom', 'geom2') %>%
    mutate(
        geom = factor(geom, levels = unique(geom)),
        geom2 = factor(geom2, levels = unique(geom2))        
    ) %>%
    group_by(geom) %>%
    ggplot(aes(geom, geom2, fill = value)) +
         geom_tile() +
         scale_fill_viridis(name = bquote(cos(theta))) +
         theme(
             axis.text.y = element_text(size = 8)   ,
             axis.text.x = element_text(size = 8, hjust = 1, vjust = 1, angle = 45),   
             legend.position = 'bottom',
             legend.key.height = grid::unit(.2, 'cm'),
             legend.key.width = grid::unit(.7, 'cm'),
             axis.title = element_text(color = 'gray55')                
         ) +
         labs(
             title = &quot;ggplot2 Geom Cosine Similarity&quot;,
             subtitle = 'Geoms with similar aesthetics are clustered together along the diagonal.',
             x = 'Geom',
             y = 'Geom'
         )
</pre>
<p><img data-orig-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_sim2.png?w=456" data-orig-size="2172,2197" data-medium-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_sim2.png?w=456?w=297" data-attachment-id="2271" data-image-meta="{" data-image-description="" src="https://trinkerrstuff.files.wordpress.com/2018/03/geom_sim2.png?w=456" data-permalink="https://trinkerrstuff.wordpress.com/2018/03/21/ggplot2-how-geoms-aesthetics-%e2%89%88-whipped-cream/geom_sim2/" data-large-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_sim2.png?w=456?w=640" alt="geom_sim2" data-image-title="geom_sim2" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-2271" data-recalc-dims="1"></p>
<p>This seemed less interesting. I didn’t really have a plausible explanation for what patterns did show up and for the most part, clusters became really large or really small. I’m open to others’ interpretations.</p>
<h2>A Few Un-/Re-discovered ggplot2 Features</h2>
<p>I did want to learn more about <code>geom_count</code> &amp; <code>geom_spoke</code> in the remaining exploration.</p>
<pre>
?geom_count

ggplot(diamonds, aes(x = cut, y = clarity)) + 
    geom_count(aes(size = ..prop.., group = 1)) +
    scale_size_area(max_size = 10)
</pre>
<p><img data-orig-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_count1.png?w=456" data-orig-size="1684,1457" data-medium-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_count1.png?w=456?w=300" data-attachment-id="2272" data-image-meta="{" data-image-description="" src="https://trinkerrstuff.files.wordpress.com/2018/03/geom_count1.png?w=456" data-permalink="https://trinkerrstuff.wordpress.com/2018/03/21/ggplot2-how-geoms-aesthetics-%e2%89%88-whipped-cream/geom_count-2/" data-large-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_count1.png?w=456?w=640" alt="geom_count" data-image-title="geom_count" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-2272" data-recalc-dims="1"></p>
<p>Oh yeah! Now I remember. A shortcut to make the <code>geom_point</code> bubble plot for investigating categorical variable covariance as an alternative to the heatmap.</p>
<pre>
?geom_spoke

df &lt;- expand.grid(x = 1:10, y=1:10)
df$angle &lt;- runif(100, 0, 2*pi)
df$speed &lt;- runif(100, 0, sqrt(0.1 * df$x))

ggplot(df, aes(x, y)) +
    geom_point() +
    geom_spoke(aes(angle = angle), radius = 0.5)

</pre>
<p><img data-orig-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_spoke.png?w=456" data-orig-size="1684,1457" data-medium-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_spoke.png?w=456?w=300" data-attachment-id="2273" data-image-meta="{" data-image-description="" src="https://trinkerrstuff.files.wordpress.com/2018/03/geom_spoke.png?w=456" data-permalink="https://trinkerrstuff.wordpress.com/2018/03/21/ggplot2-how-geoms-aesthetics-%e2%89%88-whipped-cream/geom_spoke/" data-large-file="https://trinkerrstuff.files.wordpress.com/2018/03/geom_spoke.png?w=456?w=640" alt="geom_spoke" data-image-title="geom_spoke" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-2273" data-recalc-dims="1"></p>
<p>Interesting. The documentation says:</p>
<blockquote>
<p>…useful when you have variables that describe direction and distance.</p>
</blockquote>
<p>Not sure if I have a use case for my own work. But I’ll store it in the vault (but better than I remembered <code>geom_count</code>). </p>
<h2>Learning More About Geoms &amp; Aesthetics</h2>
<p>I wanted to leave people with a quick reference guide that RStudio has kindly provided to help give quick reference to geoms and aesthetics and whe to use them.</p>
<p><a rel="nofollow" href="https://www.rstudio.com/wp-content/uploads/2016/11/ggplot2-cheatsheet-2.1.pdf" target="_blank"><br>
<img alt="Image result for all ggplot geoms" src="https://i2.wp.com/www.dartistics.com/images/ggplot2_geoms.png"><br>
</a></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://trinkerrstuff.wordpress.com/2018/03/21/ggplot2-how-geoms-aesthetics-%E2%89%88-whipped-cream/"> R – TRinker's R Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/GxkQch2dopc" height="1"></a></div>