<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/gender-diversity-analysis-of-data-science-industry-using-kaggle-survey-dataset-in-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://datascienceplus.com/gender-diversity-analysis-of-data-science-industry-using-kaggle-survey-dataset-in-r/"> R Programming – DataScience+</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a rel="nofollow" href="https://www.kaggle.com/kaggle/kaggle-survey-2017" target="_blank">Kaggle</a> recently released the dataset of an industry-wide survey that it conducted with 16K respondents. </p>
<p>This article aims to understand how the argument of Gender Diversity plays out in Data Science Practice. </p>
<p>Disclaimer: Yes, I understand this dataset is not the output of a Randomized Experiment hence cannot be a representative of the entire Data Science Practitioners and also contains Selection bias, which I’m well aware. Let us proceed further with this disclaimer in mind. </p>
<p><b>Loading required R packages:</b></p>
<pre>
#Loading Required Libraries 
library(dplyr)
library(stringr)
library(ggplot2)
library(ggthemes)
library(tidyr)
library(scales)
</pre>
<p>We are going to deal with only <code>multipleChoiceResponses.csv</code> dataset from the downloaded files and let us load it into our R environment.</p>
<pre>
#Load Input Data
complete_data &lt;- read.csv(&quot;.../multipleChoiceResponses.csv&quot;,header =T, stringsAsFactors = F)
</pre>
<p>The very first thing we would check is how is the Gender distribution of the respondents. </p>
<pre>
#Gender Distribution
complete_data %>% 
  filter(GenderSelect!='') %>% 
  group_by(GenderSelect) %>% 
  count() %>% 
  ggplot(aes(x = GenderSelect,y = (n / sum(n))*100))+
  geom_bar(stat = 'identity') + ylab('Percent') + theme_solarized() +
  theme(axis.text = element_text(size = 6)) + ggtitle('Gender Distribution of Kaggle Survey Respondents')
</pre>
<p>Gives this plot:<br>
<a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2017/11/Rplot001.png?ssl=1" target="_blank"><img sizes="(max-width: 490px) 100vw, 490px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/11/Rplot001-490x261.png?w=450&ssl=1" alt="" class="wp-image-9620" data-recalc-dims="1"></a></p>
<p>With no surprise like many other Technical domain, Data Science is also dominated by Male Gender with more than 80% respondents being Male and less than 20% being Female. How about the split of Male and Female across countries of the participants. </p>
<pre>
complete_data %>% filter(GenderSelect %in% c('Male','Female')) %>%
  group_by(Country,GenderSelect) %>% 
  summarise(count = n()) %>%
  arrange(desc(count)) %>% ggplot() + 
  geom_bar(aes(Country,count, fill = GenderSelect), stat = 'identity') +
  #facet_grid(.~GenderSelect)  + 
  theme_solarized() +
  theme(axis.text = element_text(size = 9),
        axis.text.x = element_text(angle = 40, vjust = 0.5, hjust = 0.5)) +
  ggtitle('Country wise Survey Respondends - M/F') 
</pre>
<p>Gives this plot:<br>
<a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2017/11/Rplot002.png?ssl=1" target="_blank"><img sizes="(max-width: 490px) 100vw, 490px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/11/Rplot002-490x261.png?w=450&ssl=1" alt="" class="wp-image-9622" data-recalc-dims="1"></a></p>
<p>With the US being the top country of Respondents followed by India, We can see how Male-Female split across Countries look like. While this chart very well represents the distribution of countries, it doesn’t reflect which country is doing good in terms of Female Gender in Data Science. To understand that, Let us create a new KPI – F2M Ratio (Female to Male Ratio % – which could be interpreted as the number of Female to 100 Male).</p>
<pre>
complete_data %>% filter(GenderSelect %in% c('Male','Female') &amp; Country!=&quot;&quot;) %>%
  group_by(Country,GenderSelect) %>% 
  summarise(count = n()) %>%
  spread(GenderSelect,count) %>% 
  mutate(F2M = (Female/Male)*100) %>% 
  arrange(desc(F2M)) %>%
  #mutate(F2M = percent(F2M)) %>% 
  ggplot() +
  geom_bar(aes(Country,F2M, fill = F2M), stat = 'identity') +
theme_solarized() +
  theme(axis.text = element_text(size = 9),
        axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 0.5)) +
  ggtitle('Female to Male Ratio - Country Wise') + scale_fill_continuous_tableau()
</pre>
<p>Gives this plot:<br>
<a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2017/11/Rplot003.png?ssl=1" target="_blank"><img sizes="(max-width: 490px) 100vw, 490px" src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2017/11/Rplot003-490x261.png?w=450&ssl=1" alt="" class="wp-image-9624" data-recalc-dims="1"></a></p>
<p>It turns out that no Country has got this Female-to-Male ratio more than 50% which is not a very healthy insight, but there are three countries that fared above 40% – Ireland, Malaysia and Egypt are those. Ironically, The US and India that were on the top overall have got lesser than 30% and 20% respectively.</p>
<p>Let us see how the Age distribution looks between Male and Female:</p>
<pre>
complete_data %>% filter(GenderSelect %in% c('Male','Female')) %>%  
  ggplot() + geom_histogram(aes(Age),binwidth = 1) + 
  theme_solarized() + facet_grid(.~GenderSelect) +
  ggtitle('Age Distribution - Male vs Female')
</pre>
<p>Gives this plot:<br>
<a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2017/11/Rplot006.png?ssl=1" target="_blank"><img sizes="(max-width: 490px) 100vw, 490px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/11/Rplot006-490x261.png?w=450&ssl=1" alt="" class="wp-image-9625" data-recalc-dims="1"></a></p>
<p>It could be inferred from the above Plot that the central tendency between Male and Female is similar, but it is very clear that Men seemed to start earlier than their Female counterparts – which could be a big factor to establish themselves in this industry with confidence. </p>
<p>And finally, What is the language that’s been familiar among Data Enthusiasts. </p>
<pre>
complete_data %>% group_by(LanguageRecommendationSelect) %>% summarize(count = n())
<em># A tibble: 14 x 2
LanguageRecommendationSelect count 1 5718
2 C/C++/C# 307
3 F# 4
4 Haskell 17
5 Java 138
6 Julia 30
7 Matlab 238
8 Other 85
9 Python 6941
10 R 2643
11 SAS 88
12 Scala 94
13 SQL 385
14 Stata 28
</em></pre>
<p>The answer becomes the obvious one – Python followed by R (Remember the Selection bias disclaimer). So, what’s the language that does well with our Female Data Enthusiasts:</p>
<pre>
complete_data %>% filter(GenderSelect %in% c('Male','Female')) %>% group_by(LanguageRecommendationSelect,GenderSelect) %>% 
  summarize(count = n()) %>%
  spread(GenderSelect,count) %>% 
  mutate(F2M = Female/Male) %>% 
  arrange(desc(F2M)) %>%
  mutate(F2M = F2M * 100) %>%  ggplot() +
  geom_bar(aes(LanguageRecommendationSelect,F2M, fill = F2M), stat = 'identity') +
  theme_solarized() + 
  theme(axis.text = element_text(size = 9),
        axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 0.5)) +
  scale_fill_continuous_tableau() + ggtitle('F2M Ratio of Languages used by Kagglers')
</pre>
<p>Gives this plot:<br>
<a rel="nofollow" href="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/11/Rplot007.png?ssl=1" target="_blank"><img sizes="(max-width: 490px) 100vw, 490px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2017/11/Rplot007-490x261.png?w=450&ssl=1" alt="" class="wp-image-9626" data-recalc-dims="1"></a></p>
<p><code>Stata</code> has very well outperformed R and Python with Female Data Enthusiasts and the possible explanation for this could be the increased penetration of Stata as a language in Academia and Research. </p>
<p>Well, that’s a simple Gender Diversity Analysis of Data Science Industry with Kaggle Dataset. The entire code used here is available on <a rel="nofollow" href="https://github.com/amrrs/Diversity_analysis_Kaggle_Survey/blob/master/kaggle-data.R" target="_blank">my Github</a>. </p>
<p><b>References:</b></p>
<ul>
1. <a rel="nofollow" href="https://www.kaggle.com/kaggle/kaggle-survey-2017" target="_blank">Kaggle Survey Dataset</a><br>
2. <a rel="nofollow" href="https://www.kaggle.com/nulldata/diversity-analysis-of-kaggle-survey-dataset-in-r/" target="_blank">Kaggle Kernel of this Analysis</a></ul>
<ul></ul>
<p><strong>
<p>Related Post</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/how-happy-is-your-country-visualized/" title="Permanent Link toHow Happy is Your Country? — Happy Planet Index Visualized" target="_blank">How Happy is Your Country? — Happy Planet Index Visualized</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/exploring-clustering-and-mapping-torontos-crimes/" title="Permanent Link toExploring, Clustering, and Mapping Toronto’s Crimes" target="_blank">Exploring, Clustering, and Mapping Toronto’s Crimes</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/spring-budget-2017-circle-visualisation/" title="Permanent Link toSpring Budget 2017: Circle Visualisation" target="_blank">Spring Budget 2017: Circle Visualisation</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/qualitative-research-in-r/" title="Permanent Link toQualitative Research in R" target="_blank">Qualitative Research in R</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/multi-dimensional-reduction-and-visualisation-with-t-sne/" title="Permanent Link toMulti-Dimensional Reduction and Visualisation with t-SNE" target="_blank">Multi-Dimensional Reduction and Visualisation with t-SNE</a></li>
</ol>
	<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://datascienceplus.com/gender-diversity-analysis-of-data-science-industry-using-kaggle-survey-dataset-in-r/"> R Programming – DataScience+</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 width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/XNdIB5OJPzI" height="1"></a></div>