<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/who-tuberculosis-data-ggplot2/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://eugejjoh.wordpress.com/2017/03/03/who-tuberculosis-data-ggplot2/"> R – Incidental Ideas</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>So it has been a while since my <a target="_blank" rel="nofollow" href="https://eugejjoh.wordpress.com/2017/02/02/unhcr-refugee-data-visualized/">previous post</a> on some data taken from the UNHCR database. This post we’ll bring it back to the topic of infectious diseases (check out my other posts on the <a target="_blank" rel="nofollow" href="https://eugejjoh.wordpress.com/2017/01/04/sir-model-with-desolve-ggplot2/">SIR model</a> and <a target="_blank" rel="nofollow" href="https://eugejjoh.wordpress.com/2017/01/24/descriptive-analysis-of-mlst-data-for-mrsa/">MRSA typing</a>). For this post, as similar to previous ones, I give a guide through the process I took to organize the data, a nifty function I created to search the documentation and a visualization of the data using <strong>ggplot2</strong>.</p>
<figure data-shortcode="caption" class="wp-caption"><img sizes="(max-width: 300px) 85vw, 300px" data-image-description="" data-orig-file="https://eugejjoh.files.wordpress.com/2017/03/mycobacterium20tuberculosis20030.jpg" data-orig-size="650,520" data-image-title="mycobacterium20tuberculosis20030" class="wp-image-1614" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="1614" data-permalink="https://eugejjoh.wordpress.com/?attachment_id=1614" alt="mycobacterium20tuberculosis20030" data-medium-file="https://i0.wp.com/eugejjoh.files.wordpress.com/2017/03/mycobacterium20tuberculosis20030.jpg?resize=300%2C240&amp;ssl=1" data-large-file="https://eugejjoh.files.wordpress.com/2017/03/mycobacterium20tuberculosis20030.jpg?w=650" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/eugejjoh.files.wordpress.com/2017/03/mycobacterium20tuberculosis20030.jpg?resize=300%2C240&ssl=1"><br>
<figcaption class="wp-caption-text">Electron micrograph of Mycobacterium tuberculosis</figcaption>
</figure>
<h2>What is Tuberculosis?</h2>
<p><strong>Tuberculosis</strong> (TB) is a nasty disease caused by the bacterium <em>Mycobacterium tuberculosis</em>. It was first described by Hippocrates and has a history concurrent with human civilization. Individuals infected with TB usually do not develop active disease but if they develop active TB, they can on average infect <em><strong>8-10 </strong></em>people. Most of the time when we hear of TB, we think of the infection within the lungs, but I learned during my time volunteering in a medical clinic in Peru that TB can manifest in other sites of the body (extra-pulmonary TB). This bacterium has infected roughly a third of the world’s population and is a top 10 cause of death around the globe.</p>
<p>There are two major modern concerns with TB…</p>
<ol>
<li><strong>TB and HIV co-infection</strong>, where there is a disproportionate mortality rate by TB with HIV infected individuals. HIV infects CD4+ T-cells, which are essential for an appropriate immune response to combat TB. This relationship has been <a target="_blank" rel="nofollow" href="http://jamanetwork.com/journals/jama/article-abstract/400119">reported</a> in patients.</li>
<li><strong>Multi-drug resistant TB</strong> (MDR-TB) is a growing public health concern that threatens the control of TB infection throughout the world. There have been reports of <a target="_blank" rel="nofollow" href="https://www.cdc.gov/tb/publications/factsheets/drtb/xdrtb.htm">extensive-drug resistant TB</a> (XDR-TB) which is resistant to the standard treatment of isoniazid and rifampin alongside any fluoroquinolone and at least one secondary-treatment drug. Fewer treatment options put patients under rigorous and strenuous regimens and present a risk of transmission to others.</li>
</ol>
<h2>Data Retrieval</h2>
<p>The data I used for this post is taken from the World Health Organization from <a target="_blank" rel="nofollow" href="http://www.who.int/tb/country/data/download/en/">this link to the TB data</a>. Specifically I used the <strong>data dictionary</strong> and <strong>TB burden estimates</strong>.<strong> </strong>When you click these links, they generate a comma-delimited file (.csv) and date-stamp the file. I downloaded these files back in February 2016. Just remember where you save these in your local directory so you can read them into R for the near future.</p>
<h2>Getting Started</h2>
<p>The code I use for my posts can be found on <a target="_blank" rel="nofollow" href="https://github.com/eugejoh/">my GitHub account</a>, open for free use and adaptation. I’m always open to comments and suggestions on how to improve my code or even a completely different method to reach the same goal. Optimization of R programming is something I am working towards bit by bit.</p>
<p>After setting up your working directory, read your comma-delimited files using the <strong>read.csv()</strong> function. The WHO files are conveniently formatted so there is no need for elaborate arguments for headers, field separators or assigning missing values.</p>
<pre>
TB.burden &lt;- read.csv(&quot;TB_burden_countries_2016-02-18.csv&quot;) #TB burden dataset
TB.dic &lt;- read.csv(&quot;TB_data_dictionary_2016-02-18.csv&quot;) #TB documentation dictionary
</pre>
<h2>Customized Search Function</h2>
<p>While completing an R assignment for one of my classes, I ran into the <strong>readline()</strong> <a target="_blank" rel="nofollow" href="https://stat.ethz.ch/R-manual/R-devel/library/base/html/readline.html">function</a> which allows for some interactive functionality within R. The reason I created this interactive custom search function is because of the fact that the column variables in the TB burden .csv file are not completely straightforward and it’s annoying to manually search through the file itself in Microsoft Excel. So instead of memorizing all of them (only to forget after I write 10 lines of code), I decided to create this function whenever I start to write code for a new plot and need to remind myself the exact description of the variable I am working with…</p>
<pre>
TB.search &lt;- function (x){ #
look &lt;- names(x) #assign the names/column names of the subsetted data
message(&quot;Matching variable names found in the documentation files&quot;)
TB.d &lt;- as.character(TB.dic[,4]) # conversion to character to have &quot;clean&quot; output
out &lt;- look[look %in% TB.dic[,1]] #assignment of vector: which names of the selected subset are in the documentation file
print(out) #check which variable names from dictionary match the input
message(&quot;Above includes all names for variable names found in the documentation files&quot;) #message prompt for output

z &lt;- readline(&quot;Search Variable Definition (CASE-SENSITIVE): &quot;) #interactive read-in of variable name
if (z %in% out){ # NEED TO MAKE THE CONDITION TO SEPARATE integer(0) from real integer values
print(TB.d[grep(paste0(&quot;^(&quot;,z,&quot;){1}?&quot;),TB.dic[,1])]) #print the definition found in TB.d
}else{

repeat{ #repeat the line below for readline() if exact match of doesn't exist
y&lt;-readline(&quot;Please re-input (press 'ESC' to exit search): &quot;) #second prompt
if (y %in% out) break # the condition that ends the repeat, that the input matches a name in the documentation
}
print(TB.d[grep(paste0(&quot;^&quot;,y,&quot;{1}?&quot;),TB.dic[,1])]) #print the definition found in documentation file TB.dic
}
}
</pre>
<p>I’m only going to highlight a couple things in the code above. I converted the definitions found in the documentation file because the original data type was a <strong>factor</strong>. This was a problem with the print output because it would show all the unnecessary information on the number of factors and values of the factors I had no interest in. Secondly I ended up using a <strong>repeat</strong> in my <strong>if</strong> statement to prompt the user if they incorrectly typed in a variable name in the console. This <a target="_blank" rel="nofollow" href="https://www.programiz.com/r-programming/repeat-loop">link</a> provides some helpful information on the <strong>repeat</strong> loop. Other then that, I used <a target="_blank" rel="nofollow" href="http://www.endmemo.com/program/R/grep.php">regular expression</a> to specify the search to match what was actually in the documentation file.</p>
<h2>Cleaning Data</h2>
<p>As with all data, it doesn’t come in the form that you always want it in. Luckily the WHO TB data wasn’t in bad shape and I just converted all <strong>integer</strong> valued columns into <strong>numeric</strong> types using a simple loop. (<em>Comment if you know how to do this using the <strong>apply</strong> family!</em>)</p>
<pre>
for (k in 1:length(names(TB.burden))){ #convert all the rows with type 'integer' to 'numeric
if (is.integer(TB.burden[,k])){
TB.burden[,k] &lt;- as.numeric(TB.burden[,k])
}
}
</pre>
<p>After that, I used the <strong><a target="_blank" rel="nofollow" href="http://www.cookbook-r.com/Manipulating_data/Renaming_levels_of_a_factor/">mapvalues</a></strong> function from the <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/plyr/index.html"><strong>plyr</strong> package</a> to change the levels in the country variable. I used this because the basic functions in R require me to specify all the levels in the factor and using 219 country names seemed tedious. Quite simply, I just listed the old names I wanted to change and created a respective character vector of the the new country names.</p>
<pre>
library(plyr)
TB.burden$country &lt;- (mapvalues((TB.burden$country), from = c(
&quot;Bolivia (Plurinational State of)&quot;,
&quot;Bonaire, Saint Eustatius and Saba&quot;,
&quot;China, Hong Kong SAR&quot;,
&quot;China, Macao SAR&quot;,
&quot;Democratic People's Republic of Korea&quot;,
&quot;Democratic Republic of the Congo&quot;,
&quot;Iran (Islamic Republic of)&quot;,
&quot;Lao People's Democratic Republic&quot;,
&quot;Micronesia (Federated States of)&quot;,
&quot;Republic of Korea&quot;,
&quot;Saint Vincent and the Grenadines&quot;,
&quot;Sint Maarten (Dutch part)&quot;,
&quot;The Former Yugoslav Republic of Macedonia&quot;,
&quot;United Kingdom of Great Britain and Northern Ireland&quot;,
&quot;United Republic of Tanzania&quot;,
&quot;Venezuela (Bolivarian Republic of)&quot;,
&quot;West Bank and Gaza Strip&quot;)

, to = c(
&quot;Bolivia&quot;,
&quot;Caribbean Netherlands&quot;,
&quot;Hong Kong&quot;,
&quot;Macao&quot;,
&quot;North Korea&quot;,
&quot;DRC&quot;,
&quot;Iran&quot;,
&quot;Laos&quot;,
&quot;Micronesia&quot;,
&quot;South Korea&quot;,
&quot;St. Vincent &amp;amp;amp;amp;amp; Grenadines&quot;,
&quot;Sint Maarten&quot;,
&quot;Former Yugoslav (Macedonia)&quot;,
&quot;UK &amp;amp;amp;amp;amp; Northern Ireland&quot;,
&quot;Tanzania&quot;,
&quot;Venezuela&quot;,
&quot;West Bank and Gaza&quot;)
))
</pre>
<p>I threw in some random subsetting into the code to pull out values for specific questions (ie. what was the estimated prevalence per 100,000 people of TB in Peru during 2014). You can see it in the actual code in the <a target="_blank" rel="nofollow" href="https://github.com/eugejoh/WHO-TB-Data/blob/master/TB-WHO-post.R">GitHub repository</a>.</p>
<h2>Visualizing Data</h2>
<p>I was interested in what estimated rates of TB were <strong>by WHO region</strong>, so I ran a simple loop to assign new variable names to each region (<em>this is not the best practice IMO but it does the trick</em>).</p>
<pre>
for (i in levels(TB.burden$g_whoregion)){ #selection of the WHO regions (AFR, AMR, EMR, EUR, SEA, WPR)
nam &lt;- paste0(i,&quot;_whoregion&quot;) #creation of the name based on acronyms from levels
assign(nam, subset(TB.burden,TB.burden$g_whoregion %in% paste(i))) #assigning each level a subset based on the region
}
ls() #just to show what variables are stored...
#look for AFR_whoregion, AMR_whoregion, EMR_whoregion, EUR_whoregion, SEA_whoregion, WPR_whoregion
</pre>
<p>Now we set up the themes we want to use for <strong>ggplot2</strong>. I set the year scale for the legends, customized the text on the axes and assigned <strong>dark_t</strong> to be a dark, black-grey background and <strong>light_t</strong> as a simple, white-grey background theme.</p>
<pre>
ctext &lt;- theme(axis.ticks = element_blank(),
plot.title=element_text(family=&quot;Verdana&quot;),
axis.text.x=element_text(size=9,family=&quot;Verdana&quot;), #http://www.cookbook-r.com/Graphs/Fonts/#table-of-fonts
axis.title.x=element_text(size=10)
axis.text.y=element_text(size=7.5,family=&quot;Verdana&quot;),
axis.title.y-element_text(size=10,family=&quot;Verdana&quot;),
legend.title=element_text(size=9,family=&quot;Verdana&quot;,vjust=0.5), #specify legend title color
legend.text=element_text(size=7,family=&quot;Verdana&quot;,face=&quot;italic&quot;),
)

dark_t &lt;- theme_minimal()+
theme(
plot.background = element_rect(fill=&quot;#191919&quot;), #plot background
panel.border = element_blank(), #removes border
panel.background = element_rect(fill = &quot;#000000&quot;,colour=&quot;#000000&quot;,size=2), #panel background and border
panel.grid = element_line(colour = &quot;#333131&quot;), #panel grid colours
panel.grid.major = element_line(colour = &quot;#333131&quot;), #panel major grid color
panel.grid.minor = element_blank(), #removes minor grid

plot.title=element_text(size=16, face=&quot;bold&quot;,family=&quot;Verdana&quot;,hjust=0,vjust=1,color=&quot;#E0E0E0&quot;), #set the plot title
plot.subtitle=element_text(size=12,face=c(&quot;bold&quot;,&quot;italic&quot;),family=&quot;Verdana&quot;,hjust=0.01,color=&quot;#E0E0E0&quot;), #set subtitle

axis.text.x = element_text(size=9,angle = 0, hjust = 0.5,vjust=1,margin=margin(r=10),colour=&quot;#E0E0E0&quot;), # axis ticks
axis.title.x = element_text(size=11,angle = 0,colour=&quot;#E0E0E0&quot;), #axis labels from labs() below
axis.text.y = element_text(size=9,margin = margin(r=5),colour=&quot;#E0E0E0&quot;), #y-axis labels

legend.title=element_text(size=11,face=&quot;bold&quot;,vjust=0.5,colour=&quot;#E0E0E0&quot;), #specify legend title color
legend.background = element_rect(fill=&quot;#262626&quot;,colour=&quot;#383838&quot;, size=.5), #legend background and cborder
legend.text=element_text(colour=&quot;#E0E0E0&quot;)) + #legend text colour
# plot.margin=unit(c(t=1,r=1.2,b=1.2,l=1),&quot;cm&quot;)) #custom margins
ctext

light_t &lt;- theme(legend.background = element_rect(fill=&quot;grey95&quot;,colour=&quot;grey70&quot;, size=.5),
plot.title=element_text(size=16, face=&quot;bold&quot;,family=&quot;Verdana&quot;,hjust=0,vjust=1), #set the plot title
plot.subtitle=element_text(size=12,face=c(&quot;bold&quot;,&quot;italic&quot;),family=&quot;Verdana&quot;,hjust=0.01), #set subtitle

panel.grid.minor = element_blank()) + #removes minor grid)
ctext

# specify scale for year variable
year.scale &lt;- c(1990,1995,2000,2005,2010,2014) # used for breaks below

</pre>
<p>For the next plots, I’ll only be focusing on the WHO Region of Africa. Two notes on the code below for the plots: <strong>1)</strong> I used the <a target="_blank" rel="nofollow" href="https://blog.rstudio.org/2016/11/14/ggplot2-2-2-0/"><strong>forcats</strong> package</a> to reverse the order of the countries on the y-axis. This package is useful when using <strong>ggplot2</strong> for categorical data. <strong>2)</strong> For the legend scales, I used the <strong>comma()</strong> function in the <strong>scales</strong> package to include the comma’s for every thousand. The following code displays the estimated prevalence, mortality and incidence (per 100,000 people) for cases from each country in the WHO Africa Region.</p>
<pre>
#PREVALENCE per 100k
library(forcats) #https://blog.rstudio.org/2016/11/14/ggplot2-2-2-0/
pAFR &lt;-ggplot(AFR_whoregion,aes(y=fct_rev(country),x=e_prev_100k)) + # prevalence (100k)
labs(title=&quot;WHO | Tuberculosis Data&quot;,
subtitle=&quot;Africa Region&quot;, x=&quot;Estimated Prevalence (per 100,000)&quot;,y=&quot;&quot;,colour=&quot;#E0E0E0&quot;) +
geom_point(shape=20,aes(colour=year,fill=year),alpha=0.6,size=3) +
scale_y_discrete(expand=c(0.002, 1))+
scale_x_continuous(limits=c(0,1500),labels=scales::comma)+
scale_fill_gradient(guide_legend(title=&quot;Year&quot;),breaks=year.scale,low=&quot;#F9FA00&quot;,high=&quot;#8C00E6&quot;) + #assigns colours to fill in aes
scale_colour_gradient(guide_legend(title=&quot;Year&quot;),breaks=year.scale,low=&quot;#F9FA00&quot;,high=&quot;#8C00E6&quot;) + #assigns colours to colour in aes
dark_t

#MORTALITY (including HIV) per 100k e_inc_tbhiv_100k
mAFR &lt;- ggplot(AFR_whoregion,aes(y=fct_rev(country),x= e_mort_exc_tbhiv_100k)) + # Mortality exclude HIV (100k)
labs(title=&quot;WHO | Tuberculosis Data&quot;,
subtitle=&quot;Africa Region&quot;,x=&quot;Estimated Mortality excluding HIV (per 100,000)&quot;,y=&quot;&quot;,colour=&quot;#E0E0E0&quot;)+
geom_point(shape=20,aes(colour=year,fill=year),alpha=0.6,size=3) +
scale_y_discrete(expand=c(0.002, 1)) +
#scale_x_continuous(limits=c(0,250),labels=scales::comma) +
scale_fill_gradient(guide_legend(title=&quot;Year&quot;),breaks=year.scale,low=&quot;#F9FA00&quot;,high=&quot;#8C00E6&quot;) + #assigns colours to fill in aes
scale_colour_gradient(guide_legend(title=&quot;Year&quot;),breaks=year.scale,low=&quot;#F9FA00&quot;,high=&quot;#8C00E6&quot;) + #assigns colours to colour in aes
dark_t

#INCIDENCE per 100k
iAFR &lt;- ggplot(AFR_whoregion,aes(y=fct_rev(country),x= e_inc_100k)) + # Mortality exclude HIV (100k)
labs(title=&quot;WHO | Tuberculosis Data&quot;,
subtitle=&quot;Africa Region&quot;,x=&quot;Estimated Incidence (per 100,000)&quot;,y=&quot;&quot;,colour=&quot;#E0E0E0&quot;)+
geom_point(shape=20,aes(colour=year,fill=year),alpha=0.6,size=3) +
scale_y_discrete(expand=c(0.002, 1)) +
scale_x_continuous(limits=c(0,1500),labels=scales::comma) +
scale_fill_gradient(guide_legend(title=&quot;Year&quot;),breaks=year.scale,low=&quot;#F9FA00&quot;,high=&quot;#8C00E6&quot;) + #assigns colours to fill in aes
scale_colour_gradient(guide_legend(title=&quot;Year&quot;),breaks=year.scale,low=&quot;#F9FA00&quot;,high=&quot;#8C00E6&quot;) + #assigns colours to colour in aes
dark_t
</pre>
<p>Now the plots in the order of estimated prevalence, incidence and mortality… (you can click them to open the full images)</p>
<p><a target="_blank" rel="nofollow" href="https://i2.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_prev_tb1.png?ssl=1"><img sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" data-image-description="" data-orig-file="https://i2.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_prev_tb1.png?w=456&amp;ssl=1" data-orig-size="2200,4000" data-image-title="afr_prev_tb" data-comments-opened="1" class="wp-image-1575" data-recalc-dims="1" data-attachment-id="1575" data-permalink="https://eugejjoh.wordpress.com/?attachment_id=1575" alt="afr_prev_tb" data-medium-file="https://i2.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_prev_tb1.png?w=456&amp;ssl=1?w=165" data-large-file="https://i2.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_prev_tb1.png?w=456&amp;ssl=1?w=563" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i2.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_prev_tb1.png?w=456&ssl=1"></a></p>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_inc_tb1.png?ssl=1"><img sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" data-image-description="" data-orig-file="https://i1.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_inc_tb1.png?w=456&amp;ssl=1" data-orig-size="2200,4000" data-image-title="afr_inc_tb" data-comments-opened="1" class="wp-image-1573" data-recalc-dims="1" data-attachment-id="1573" data-permalink="https://eugejjoh.wordpress.com/?attachment_id=1573" alt="afr_inc_tb" data-medium-file="https://i1.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_inc_tb1.png?w=456&amp;ssl=1?w=165" data-large-file="https://i1.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_inc_tb1.png?w=456&amp;ssl=1?w=563" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i1.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_inc_tb1.png?w=456&ssl=1"></a></p>
<p><a target="_blank" rel="nofollow" href="https://i0.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_mort_tb_exc_hiv1.png?ssl=1"><img sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" data-image-description="" data-orig-file="https://i0.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_mort_tb_exc_hiv1.png?w=456&amp;ssl=1" data-orig-size="2200,4000" data-image-title="afr_mort_tb_exc_hiv" data-comments-opened="1" class="wp-image-1574" data-recalc-dims="1" data-attachment-id="1574" data-permalink="https://eugejjoh.wordpress.com/?attachment_id=1574" alt="afr_mort_tb_exc_hiv" data-medium-file="https://i0.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_mort_tb_exc_hiv1.png?w=456&amp;ssl=1?w=165" data-large-file="https://i0.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_mort_tb_exc_hiv1.png?w=456&amp;ssl=1?w=563" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/eugejjoh.files.wordpress.com/2017/03/afr_mort_tb_exc_hiv1.png?w=456&ssl=1"></a></p>
<p>In the plots, the color yellow refers to a year closer to 1990 where purple is more recent towards 2014. Based on this we can see the relative changes over time on the estimated TB prevalence, incidence and mortality. Let’s focus on the prevalence and incidence plots – we can see most of the countries have lower estimated TB prevalences over time. The most drastic decreases can be seen in <em>Central African Republic</em> and <em>Niger</em>. We can also see that <em>Lesotho</em>, <em>South Africa</em> and <em>Swaziland</em> have increased estimated TB prevalence during the 1990-2014 time period. <em>Namibia</em> is an interesting one because it seems that the estimated TB prevalence increased then decreased roughly half way. To accurately visualize this trend in Namibia, we would need a choose a different method to better visualize this (a simple line plot).</p>
<p><strong>Remember</strong> these plots are just a simple qualitative way to compare trends but doesn’t capture the full picture. I’ve learned that your method of visualizing data depends on which narrative of the data you want to highlight. These graphics could be used to see which countries have had the largest changes over time or as an example, identify countries who have improved (or failed) their national TB control, using estimated TB incidence as a proxy. Are TB control or prevention systems working in these countries? Based on allocated resources or programs, are the changes in line with the goals to reduce the <a target="_blank" rel="nofollow" href="http://www.who.int/tb/strategy/en/">global burden of TB</a>.</p>
<p>You can tinker with the code to select which countries or regions you want to compare. I only displayed the plots for the WHO Africa Region but the other regions also looked interesting. You can adapt this code for the other WHO regions to see what the trends look like.</p>
<p><strong><span>Closing thoughts</span></strong>: I hope this post was informative and you learned something about TB around the world. Despite this disease being preventable and curable, it remains a real threat for many people around the world. There are groups fighting TB around the world, just one close to Boston is the <strong>endTB</strong> partnership. Check out their <a target="_blank" rel="nofollow" href="http://endtb.org/">website</a> and see the groups (PIH, MSF) involved in the work of combating MDR-TB.</p>
<p>As always I’m open to comments and suggestions on improving my code and graphics. If anyone has questions related to the code – send me a message, I’ll be more than happy to help. I’ve learned so much from online resources and communities like <a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/tagged/r">StackOverflow</a> and would always want to help those new to using R.</p>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/eugejjoh.wordpress.com/1632/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/eugejjoh.wordpress.com/1632/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></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://eugejjoh.wordpress.com/2017/03/03/who-tuberculosis-data-ggplot2/"> R – Incidental Ideas</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/-Xt6W0hHcWk"></a></div>