Charting the CMV Awareness Gap

[This article was first published on Artful Analytics, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Sometimes it’s okay to use a secondary axis

Introduction

Speaking of viruses, did you know that June is National Cytomegalovirus
(CMV) Awareness Month
?
Probably not, since most people have never heard of CMV (hence the need
for a national awareness month).

CMV is a common virus that infects 50-80% of people by the time they are
40 years old. In most cases, it’s not a big deal. But if a pregnant
woman becomes infected, she can pass the virus to the unborn child,
which results in a congenital infection about 33% of the time.

Congenital CMV (cCMV) is the number one viral cause of birth defects in
children. According to National CMV
Foundation
, 1 in 200 children
are born with CMV every year. That’s roughly 30,000 children. About 1 in
5 children born with CMV infection will have moderate to severe health
problems including:

  • Hearing loss
  • Vision loss
  • Feeding issues
  • Intellectual disability
  • Microcephaly (small head or brain)
  • Cerebral Palsy
  • Seizures

Outcomes associated
with congenital CMV are wide-ranging and unpredictable.

Despite how common and potentially damaging CMV is, research shows that
only 9% of women have heard of the condition.

Awareness = prevention

Our son
Gideon

was born with congenital CMV in 2013. Like most parents, we had never
heard of cCMV until our son was diagnosed.

Because cCMV is a viral infection, it is potentially preventable during
pregnancy if you know to take certain basic
precautions
.
However, knowing to take precations requires having heard of the
condition in the first place
, which brings us back to the need for a
National CMV Awareness Month.

One of the main tactics used in CMV awareness raising efforts is to
highlight the “awareness gap” between how few women have heard of CMV
and how many children are disabled by the condition each year.

In the past, the National CMV Foundation has used the graphic below for
this purpose (Fig. 1). It nicely shows levels of awareness vs incidence
of various congenital conditions in the US, based on data from Doutre
et al. (2016)
.


Fig. 1

Recently, I was asked by the Foundation to revise this graphic to
enhance its effectiveness (not coincidentally, my
wife
is the Chair of the Scientific
Advisory Committee).

In this post, I describe my approach using
ggplot2, as well as
cowplot and
related pacakges in R.

Mind the gap

Technically speaking, Fig. 1 is what you would call a bi-directional,
mirrored, diverging, or back-to-back bar chart. It is reminiscent of
pyramid style bar
charts often used to visualize population age distributions.

I suspect that when people see Fig. 1 they have a perceptual tendency to
sum the bars together rather than take the difference between each bar.
The former is typically how a bi-directional bar chart would be
interpreted. But since the purpose of the visualization is to highlight
the CMV awareness gap, it might be better to actually plot the gap
(linear distance) between awareness and incidence of long-term health problems for cCMV in comparison
to other conditions.

So my proposed enhancement is to layer the incidence data as a series of
dots on top of an ordered bar chart representing increasing awareness on
the x-axis, and use a secondary x-axis for incidence. Layering in this
way will create a visually salient gap between awareness and incidence
for cCMV at the top of the chart, which I can further highlight with
some text annotations.

Secondary axis (of evil?)

Early versions of {ggplot2} did not include the ability to add a
secondary axis because Hadley
Wickham
believed (and probably still
believes) that using a separate, secondary axis is a fundamentally
flawed

approach.

However, more recent versions of the package have included this
functionality with the sec_axis() function described
here. I think
we can assume from the addition of this functionality that Hadley isn’t
completely averse to the use of a secondary axis in some situations when
used with caution.

Again, my rationale for using a secondary x-axis in this case is to
achieve a specific perceptual effect, to higlight the gap between cCMV
awareness and incidence of disability visually so that people viewing the chart will
say “Wow! That’s some big gap.” And I think I can achieve this without
being manipulative or misleading, becuase the gap really is quite big.

Without further ado…

Here’s how the chart looks (Fig. 2). You can download a high
resolution version here.


Fig. 2

And here’s the R code that produces the chart.

<span class="n">library</span><span class="p">(</span><span class="n">tidyverse</span><span class="p">)</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">cowplot</span><span class="p">)</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">ggtext</span><span class="p">)</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">magick</span><span class="p">)</span><span class="w">

</span><span class="c1"># Get data from Doutre et al.</span><span class="w">

</span><span class="n">df</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">tribble</span><span class="p">(</span><span class="w">
  </span><span class="o">~</span><span class="n">condition</span><span class="p">,</span><span class="w"> </span><span class="o">~</span><span class="n">awareness</span><span class="p">,</span><span class="w"> </span><span class="o">~</span><span class="n">incidence</span><span class="p">,</span><span class="w">
  </span><span class="s2">"Congenital Cytomegalovirus (CMV)"</span><span class="p">,</span><span class="w"> </span><span class="m">6.7</span><span class="p">,</span><span class="w"> </span><span class="m">6000</span><span class="p">,</span><span class="w">
  </span><span class="s2">"Congenital Toxoplasmosis"</span><span class="p">,</span><span class="w"> </span><span class="m">8.53</span><span class="p">,</span><span class="w"> </span><span class="m">400</span><span class="p">,</span><span class="w">
  </span><span class="s2">"Congenital Rubella Syndrome"</span><span class="p">,</span><span class="w"> </span><span class="m">13.27</span><span class="p">,</span><span class="w"> </span><span class="m">3</span><span class="p">,</span><span class="w">
  </span><span class="s2">"Beta Strep (Group B Strep)"</span><span class="p">,</span><span class="w"> </span><span class="m">16.91</span><span class="p">,</span><span class="w"> </span><span class="m">380</span><span class="p">,</span><span class="w">
  </span><span class="s2">"Parvovirus B19 (Fifth Disease)"</span><span class="p">,</span><span class="w"> </span><span class="m">19.63</span><span class="p">,</span><span class="w"> </span><span class="m">1045</span><span class="p">,</span><span class="w">
  </span><span class="s2">"Fetal Alcohol Syndrome"</span><span class="p">,</span><span class="w"> </span><span class="m">61.04</span><span class="p">,</span><span class="w"> </span><span class="m">1200</span><span class="p">,</span><span class="w">
  </span><span class="s2">"Spina Bifida"</span><span class="p">,</span><span class="w"> </span><span class="m">64.54</span><span class="p">,</span><span class="w"> </span><span class="m">1500</span><span class="p">,</span><span class="w">
  </span><span class="s2">"Sudden Infant Death Syndrome (SIDS)"</span><span class="p">,</span><span class="w"> </span><span class="m">78.7</span><span class="p">,</span><span class="w"> </span><span class="m">1500</span><span class="p">,</span><span class="w">
  </span><span class="s2">"Down Syndrome"</span><span class="p">,</span><span class="w"> </span><span class="m">85.44</span><span class="p">,</span><span class="w"> </span><span class="m">6000</span><span class="p">,</span><span class="w">
  </span><span class="s2">"Congenital HIV/AIDS"</span><span class="p">,</span><span class="w"> </span><span class="m">86.33</span><span class="p">,</span><span class="w"> </span><span class="m">30</span><span class="w">
</span><span class="p">)</span><span class="w">

</span><span class="c1"># Get National CMV logo</span><span class="w">

</span><span class="n">logo</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">image_read</span><span class="p">(</span><span class="s2">"https://github.com/seth-dobson/cmv-charts/blob/master/CMV-Full-Tagline-Logo_Transparent.png?raw=true"</span><span class="p">)</span><span class="w">

</span><span class="c1"># Create chart</span><span class="w">

</span><span class="n">p</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">df</span><span class="w"> </span><span class="o">%>%</span><span class="w">
  </span><span class="n">ggplot</span><span class="p">(</span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">reorder</span><span class="p">(</span><span class="n">condition</span><span class="p">,</span><span class="w"> </span><span class="n">desc</span><span class="p">(</span><span class="n">awareness</span><span class="p">)),</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">awareness</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">geom_col</span><span class="p">(</span><span class="n">fill</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"#28C1DB"</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">geom_point</span><span class="p">(</span><span class="w">
    </span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">condition</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">incidence</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="m">70</span><span class="p">),</span><span class="w">
    </span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">4</span><span class="p">,</span><span class="w">
    </span><span class="n">pch</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">21</span><span class="p">,</span><span class="w">
    </span><span class="n">fill</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"#FB791A"</span><span class="w">
  </span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">scale_y_continuous</span><span class="p">(</span><span class="w">
    </span><span class="n">sec.axis</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">sec_axis</span><span class="p">(</span><span class="w">
      </span><span class="o">~</span><span class="w"> </span><span class="n">.</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="m">70</span><span class="p">,</span><span class="w"> 
      </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Number of Children Born with the Condition Each Year (Dots)"</span><span class="p">,</span><span class="w">
      </span><span class="n">labels</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">scales</span><span class="o">::</span><span class="n">comma_format</span><span class="p">()</span><span class="w">
    </span><span class="p">)</span><span class="w">
  </span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">coord_flip</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">labs</span><span class="p">(</span><span class="w">
    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">""</span><span class="p">,</span><span class="w">
    </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Percentage of Women Who Have Heard of the Condition (Bars)"</span><span class="p">,</span><span class="w">
    </span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Awareness vs Incidence of Congenital Conditions"</span><span class="p">,</span><span class="w">
    </span><span class="n">caption</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Based on US data from Doutré SM *et al.* (2016) Losing Ground: Awareness of Congenital Cytomegalovirus 
    in the United States. *Journal of Early Hearing Detection and Intervention* 1:39-48. Chart by Artful Analytics, 
    LLC (@_sethdobson). <br>For more information, visit nationalcmv.org."</span><span class="w">
  </span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">theme_bw</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">theme</span><span class="p">(</span><span class="w">
    </span><span class="n">plot.title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">element_text</span><span class="p">(</span><span class="n">face</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"bold"</span><span class="p">,</span><span class="w"> </span><span class="n">hjust</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">.5</span><span class="p">),</span><span class="w">
    </span><span class="n">plot.caption</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">element_textbox_simple</span><span class="p">(</span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">6</span><span class="p">,</span><span class="w"> </span><span class="n">margin</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">margin</span><span class="p">(</span><span class="m">10</span><span class="p">,</span><span class="w"> </span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="m">0</span><span class="p">)),</span><span class="w">
    </span><span class="n">axis.text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">element_text</span><span class="p">(</span><span class="n">color</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"black"</span><span class="p">),</span><span class="w">
    </span><span class="n">axis.title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">element_text</span><span class="p">(</span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">10</span><span class="p">)</span><span class="w">
  </span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">background_grid</span><span class="p">(</span><span class="n">major</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"none"</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">annotate</span><span class="p">(</span><span class="w">
    </span><span class="n">geom</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"text"</span><span class="p">,</span><span class="w">
    </span><span class="n">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Number of children\nborn with CMV"</span><span class="p">,</span><span class="w">
    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">7.8</span><span class="p">,</span><span class="w">
    </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">75</span><span class="p">,</span><span class="w">
    </span><span class="n">color</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"#FB791A"</span><span class="p">,</span><span class="w">
    </span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">3</span><span class="w">
  </span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">annotate</span><span class="p">(</span><span class="w">
    </span><span class="n">geom</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"curve"</span><span class="p">,</span><span class="w"> 
    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">8.5</span><span class="p">,</span><span class="w"> 
    </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">75</span><span class="p">,</span><span class="w"> 
    </span><span class="n">xend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">10</span><span class="p">,</span><span class="w"> 
    </span><span class="n">yend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">84</span><span class="p">,</span><span class="w">
    </span><span class="n">curvature</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">-.3</span><span class="p">,</span><span class="w"> 
    </span><span class="n">arrow</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">arrow</span><span class="p">(</span><span class="n">length</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">unit</span><span class="p">(</span><span class="m">2</span><span class="p">,</span><span class="w"> </span><span class="s2">"mm"</span><span class="p">)),</span><span class="w">
    </span><span class="n">color</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"#FB791A"</span><span class="w">
  </span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">annotate</span><span class="p">(</span><span class="w">
    </span><span class="n">geom</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"text"</span><span class="p">,</span><span class="w">
    </span><span class="n">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"% of women who have\nheard of CMV"</span><span class="p">,</span><span class="w">
    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">7.8</span><span class="p">,</span><span class="w">
    </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">30</span><span class="p">,</span><span class="w">
    </span><span class="n">color</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"#28C1DB"</span><span class="p">,</span><span class="w">
    </span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">3</span><span class="w">
  </span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">annotate</span><span class="p">(</span><span class="w">
    </span><span class="n">geom</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"curve"</span><span class="p">,</span><span class="w"> 
    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">8.5</span><span class="p">,</span><span class="w"> 
    </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">30</span><span class="p">,</span><span class="w"> 
    </span><span class="n">xend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">10</span><span class="p">,</span><span class="w"> 
    </span><span class="n">yend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">7</span><span class="p">,</span><span class="w">
    </span><span class="n">curvature</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">.20</span><span class="p">,</span><span class="w"> 
    </span><span class="n">arrow</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">arrow</span><span class="p">(</span><span class="n">length</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">unit</span><span class="p">(</span><span class="m">2</span><span class="p">,</span><span class="w"> </span><span class="s2">"mm"</span><span class="p">)),</span><span class="w">
    </span><span class="n">color</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"#28C1DB"</span><span class="w">
  </span><span class="p">)</span><span class="w">

</span><span class="c1"># Combine chart with logo</span><span class="w">

</span><span class="n">ggdraw</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">draw_plot</span><span class="p">(</span><span class="n">p</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
  </span><span class="n">draw_image</span><span class="p">(</span><span class="w">
    </span><span class="n">logo</span><span class="p">,</span><span class="w"> 
    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">.075</span><span class="p">,</span><span class="w"> 
    </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">.1</span><span class="p">,</span><span class="w"> 
    </span><span class="n">scale</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">.2</span><span class="p">,</span><span class="w"> 
    </span><span class="n">hjust</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">.5</span><span class="p">,</span><span class="w"> 
    </span><span class="n">vjust</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">.5</span><span class="w">
  </span><span class="p">)</span><span class="w">
</span>

A few things to note about the code above:

  • The secondary x-axis is actually coded as a secondary y-axis since
    you have to use coord_flip() to get the categorical variable on the y-axis
    when using geom_col().
  • The sec_axis() function is used in conjuction with the sec.axis
    option within scale_y_continuous(). In order to align the two
    y-axes, I multiplied the secondary axis by 70 within sec_axis()
    and divided incidence by 70 within the aesthetics of geom_point().
    I arrived at the number 70 by trial and error. Not sure why this works,
    but it does.
  • I used the ColorZilla Google
    Chrome extension to get hex color values from the National CMV logo.
    That way I was able to match the colors in the logo to the chart
    elements without a lot of guesswork.
  • I am using the amazing
    ggtext package by Claus Wilke to render the
    plot.caption theme element in markdown, so I can easily italicize
    selected words with asterisks. The element_textbox_simple() function from
    {ggtext} also does word wrapping automatically.

Conclusion

Hopefully you will agree that my combination bar and dot chart (Fig. 2) is an
improvement on the original graph (Fig. 1) in that it highlights the CMV
awareness gap more effectively for a general audience. I also trust that
Hadley would agree that this is an acceptable use of a secondary axis.
Altough, he might not. So nobody tell him, OK?

To learn more about congenital CMV visit
nationalcmv.org.

Questions or comments?

Feel free to reach out to me at any of the social links below.

For more R content, please visit
R-bloggers and
RWeekly.org.

To leave a comment for the author, please follow the link and comment on their blog: Artful Analytics.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)