<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yahia El Gamal on Medium]]></title>
        <description><![CDATA[Stories by Yahia El Gamal on Medium]]></description>
        <link>https://medium.com/@yahiaelgamal?source=rss-7dcf53259653------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*kfY1YHIXEYj_hpbo.jpg</url>
            <title>Stories by Yahia El Gamal on Medium</title>
            <link>https://medium.com/@yahiaelgamal?source=rss-7dcf53259653------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 11:53:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yahiaelgamal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create Basic Sunburst Graphs with ggplot2]]></title>
            <link>https://medium.com/optima-blog/create-basic-sunburst-graphs-with-ggplot2-7d7484d92c61?source=rss-7dcf53259653------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d7484d92c61</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[r]]></category>
            <dc:creator><![CDATA[Yahia El Gamal]]></dc:creator>
            <pubDate>Sun, 28 Feb 2016 21:37:37 GMT</pubDate>
            <atom:updated>2017-08-11T19:10:52.624Z</atom:updated>
            <content:encoded><![CDATA[<h4>Solving polar coordinates’ biggest problem of all time (aka text positioning)</h4><p>You know my love of polar coordinates, right? I do <a href="https://medium.com/optima-blog/using-polar-coordinates-for-better-visualization-1d337b6c9dec#.59funo66x">love</a> polar coordinates.</p><p><a href="https://medium.com/p/1d337b6c9dec"></a></p><p>And I love the awesome ggplot2 by the amazing Hadley Wickham (if you are using any other visualization library, you’re missing the point).</p><p>In this short tutorial we’ll go through how to create pretty sunburst graphs (at least the basic kind). To get the basic idea, sunburst is a graph that is mainly used to display hierarchical data like a tree map but (you’ve guessed right) it’s circular! I will not talk much about the pros and cons of sunburst graphs, but you can learn a bit more about them <a href="http://www.bimeanalytics.com/sunburst.html?utm_content=buffer72694&amp;utm_medium=social&amp;utm_source=twitter.com&amp;utm_campaign=buffer">here</a> and <a href="https://blogs.office.com/2015/08/11/breaking-down-hierarchical-data-with-treemap-and-sunburst-charts/">here</a></p><p>Note that I am not wish to imply that suburst graphs are the best tool to visualize hierarchal data. Because I simply don’t think so .. but that’s another story for another day.</p><p>So let’s jump into the action. Let’s assume we have data for the population of Egypt by Governorate (you can find this data <a href="http://www.sis.gov.eg/En/Templates/Articles/tmpArticles.aspx?ArtID=9">here</a>, they removed the data, I had a copy <a href="https://gist.github.com/yahiaelgamal/9b3ffaf43036be44761a2e13acf362e6">here</a> ). The end result will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dihtqltM63wox4w2KAsqpg.png" /></figure><pre>library(ggplot2) # For awesome viz<br>library(dplyr) # For awesome data wrangling<br>library(scales) # Utilities for scales and formatting</pre><pre>pop.eg = read.csv(&#39;egypt_pop_2014.csv&#39;) # 2 cols: gov,population<br>sum_total_pop = sum(pop.eg$population)</pre><pre>firstLevel = pop.eg %&gt;% summarize(total_pop=sum(population))</pre><pre>sunburst_0 = ggplot(firstLevel) # Just a foundation<br>sunburst_1 = <br>  sunburst_0 + <br>  geom_bar(data=firstLevel, aes(x=1, y=total_pop), fill=&#39;darkgrey&#39;, stat=&#39;identity&#39;) +</pre><pre>  geom_text(aes(x=1, y=sum_total_pop/2, label=paste(&#39;Egypt in 2014  had&#39;, comma(total_pop))), color=&#39;white&#39;)</pre><pre>sunburst_1</pre><p>This code produces this (dull) bar. Notice here the `aes(x=1)` which is the trick we’ll use to do the multi-levels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QjeN6kUnHl3d36so1E6uRQ.png" /><figcaption>Don’t leave now, wait a second.</figcaption></figure><p>but when we add</p><pre>sunburst_1 + coord_polar(‘y’)</pre><p>you get the root of your sunburst. Notice that here `coord_polar` takes an argument `’y’`. Which tells it to rotate around the y axis (not the x axis).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*gix1K9jHPYa4rP88Pn2HDA.png" /></figure><p>Let’s Add a new layer for governorates</p><pre>gov_pop = pop.eg %&gt;% group_by(gov) %&gt;%<br>  summarize(total_pop=sum(population)) %&gt;%<br>  arrange(desc(total_pop))</pre><p>The trick we’re going to do here is to use stacked bar chart and then rotate them around the y axis to build to donughts. So let’s do a stacked bar charts</p><pre>sunburst_1 +<br> geom_bar(data=gov_pop,<br> aes(x=2, y=total_pop, fill=total_pop),<br> color=&#39;white&#39;, position=&#39;stack&#39;, stat=&#39;identity&#39;, size=0.6) + <br> geom_text(data=gov_pop, aes(label=paste(gov, total_pop), x=2, y=total_pop), position=&#39;stack&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Kt31h1sZPdlO-Tuert8rIQ.png" /></figure><p>Notice here the `position=’stack’`, this is the reason why ggplot positioned text properly, without it you will get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sIekwG7qF3KP_sw_7xRjOA.png" /></figure><p>which makes sense if you think about it.</p><p>Let’s do a bit of magic</p><pre>sunburst_2 + coord_polar(&#39;y&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*_STWztvHJCXOJkJPYPLKzg.png" /></figure><p>Not cool, mainly beacuse of text angles and positions. So we need to be slightly smart about it. Mainly we want text to be in the middle if each segment, and to be angled in a readable (not upside down for example).</p><p>First let’s fix the text in the middle issue. The position of the text of each governorate should be:</p><pre>cumulative_sum - current_value/2</pre><p>Let’s compute this and save it in a dataframe</p><pre>secondLevel = gov_pop %&gt;%<br>  mutate(running=cumsum(total_pop), pos=running - total_pop/2)</pre><p>So sunburst_2 should be</p><pre>sunburst_2 = sunburst_1 +<br>  geom_bar(data=secondLevel,<br>    aes(x=2, y=total_pop, fill=total_pop, stroke=3),<br>    color=&#39;white&#39;, position=&#39;stack&#39;, stat=&#39;identity&#39;)</pre><pre>sunburst_2_text = sunburst_2 +<br> geom_text(data=secondLevel,<br>   aes(label=paste(gov, comma(total_pop)), x=2, y=pos))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ADYbjLXbr2klzdv-Z5Cajw.png" /></figure><p>Better. Let’s go polar again</p><pre>sunburst_2_text + coord_polar(&#39;y&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*qEcyxlgSutH-emjWyiZOyg.png" /></figure><p>Ok, better. But still the angles are really bad. What to do about that? Let’s compute them!!</p><p>We have 4 quadrants, each one .. you know what, code is better than words</p><pre>compute_angle = function(perc){<br>  angle = -1</pre><pre>  if(perc &lt; 0.25) # 1st q [90,0]<br>    angle = 90 — (perc/0.25) * 90<br>  else if(perc &lt; 0.5) # 2nd q [0, -90]<br>    angle = (perc-0.25) / 0.25 * -90<br>  else if(perc &lt; 0.75) # 3rd q [90, 0]<br>   angle = 90 — ((perc-0.5) / 0.25 * 90)<br>  else if(perc &lt; 1.00) # last q [0, -90]<br>    angle = ((perc -0.75)/0.25) * -90</pre><pre># Or even more compact, but less readable<br>  if(perc &lt; 0.5) # 1st half [90, -90]<br>    angle = (180 - (perc/0.5) * 180) - 90<br>  else # 2nd half [90, -90]<br>    angle = (90 - ((perc - 0.5)/0.5) * 180)</pre><pre>  return(angle)<br>}<br></pre><p>Here perc is a variable ranging from 0 to 1 representing the position of the “text label” in a circle.</p><p>let’s compute and save agian.</p><pre>secondLevel = gov_pop %&gt;%<br>  mutate(running=cumsum(total_pop), pos=running — total_pop/2) %&gt;% group_by(1:n()) %&gt;% # to compute row by row<br>  mutate(angle=compute_angle((running — total_pop/2) / sum_total_pop))</pre><p>Let’s do viz again</p><pre>sunburst_2_text = sunburst_2 +<br>  geom_text(data=secondLevel, <br>    aes(label=paste(gov, comma(total_pop)),<br>    x=2, y=pos, angle=angle))</pre><pre>sunburst_3 + coord_polar(&#39;y&#39;)</pre><p>This would look like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*E-NCjikf1XFIbGeOVIp6jQ.png" /></figure><p>Notice how the text flips on the 6 o’clock to sustain readability. Pretty cool, right? Let’s change colors a bit.</p><pre>sunburst_2_text + scale_y_continuous(labels=comma) + scale_fill_continuous(low=&#39;white&#39;, high=&#39;darkred&#39;) + coord_polar(&#39;y&#39;) + theme_minimal()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*im-BtfgyxryzUKuIwVHt6A.png" /></figure><p>Of course there are many problems in the graph. For example, the crowded text for the small governorates, and the overall viz needs to be augmented with a measure of area to tell a compelling story and many more other problems …</p><blockquote>… but text angle and positioning are not any of them.</blockquote><p>I am still exploring the concept of sunbursts. Adding a new level is obvious, but I still need to explore how to draw a level with missing elements in it (to visualize depth in the hierarchy) like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*EFy4-rwzPaH9fHRnuWJDew.png" /><figcaption>taken from <a href="https://www.biostars.org/p/68215/">https://www.biostars.org/p/68215/</a></figcaption></figure><h4>I am working on a small project to visualize demographics, inequalities, density and other phenomena of the Egyptian population. If you are interested, shoot me a message.</h4><p>You can find the code used for this post on gist.github <a href="https://gist.github.com/yahiaelgamal/353c728d4ab4f0e078b4e9a5e9d57f07">here</a>.</p><p><em>We are a team of data scientists and software engineers working to help enterprises makes the most out of their data. Our projects range from data analysis to extract insights, to predictive analytics to support decision making, to scalable production ready data products. Our focus areas are (1) personalization and (2) operational efficiency.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d7484d92c61" width="1" height="1" alt=""><hr><p><a href="https://medium.com/optima-blog/create-basic-sunburst-graphs-with-ggplot2-7d7484d92c61">Create Basic Sunburst Graphs with ggplot2</a> was originally published in <a href="https://medium.com/optima-blog">Optima . Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Polar Coordinates for Better Visualization with ggplot2]]></title>
            <link>https://medium.com/optima-blog/using-polar-coordinates-for-better-visualization-1d337b6c9dec?source=rss-7dcf53259653------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d337b6c9dec</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[visualization]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Yahia El Gamal]]></dc:creator>
            <pubDate>Sun, 06 Sep 2015 23:18:40 GMT</pubDate>
            <atom:updated>2018-08-17T08:09:44.827Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been doing some reading and experimenting with data visualization. One of the things that I really liked is the usage of Polar coordinates. This is basically using a grid of circles instead of a grid of straight line like so</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7_ftBGaOgYhe-fOQo6gIpQ.png" /></figure><p>from wikipedia</p><p>What does this have to do with visualization? It can help you with comparing different values more clearly with better spacing. I will show you an example in R and ggplot2.</p><p>Imagine we want to visualize the data of mile consumption of different cars. We can use a simple bar plot like so:</p><pre>mtcars$car = row.names(mtcars)</pre><pre>p = ggplot(mtcars, aes(x=car, y=mpg, fill=mpg)) +<br>    geom_bar(binwidth=1, stat=’identity’) +theme_light() +<br>    scale_fill_gradient(low=’red’, high=’white’, limits=c(5,40)) +<br>    theme(axis.title.y=element_text(angle=0))<br>p + theme(axis.text.x = element_text(angle=45, vjust = 1, hjust=1))</pre><p>you will get this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*dzt39QsEhnHjiIBVaj4bnA.png" /><figcaption>Normal bar plot</figcaption></figure><p>With polar coordinates, you will just use</p><pre><em>p + coord_polar()</em></pre><p>And you will get this more visually pleasing and easier to compare between bars graphics (because of the difference in the value is showed by both the height and the width of the bar at the end).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*DipJD2u-CZhYBCGw1oSMVA.png" /><figcaption>Bars in polar plot</figcaption></figure><p>I first thought that polar coordinates are more of a gimmick, but the more I see/use it, the more I like it. What do you think? Let me know if you saw any good use-cases of the polar coordinate visualization.</p><p><strong>A bonus trick</strong></p><p>I don’t feel that sorting alphabetically adds any value or makes the graph more interesting than any other sorting. Let’s sort the graph by the actual mpg.</p><pre>p + coord_polar() + aes(x=reorder(car, mpg)) +<br>    theme(axis.text.x = element_text(angle=-20)) <br># text with angle to avoid name overlap</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*leJs6tn3j13cQ9_AzqnRXg.png" /><figcaption>“the world is your oyster”- kind of graphs</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d337b6c9dec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/optima-blog/using-polar-coordinates-for-better-visualization-1d337b6c9dec">Polar Coordinates for Better Visualization with ggplot2</a> was originally published in <a href="https://medium.com/optima-blog">Optima . Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Losing Faith in MOOCs]]></title>
            <link>https://medium.com/the-higher-education-revolution/losing-faith-in-moocs-942e9b5df1d3?source=rss-7dcf53259653------2</link>
            <guid isPermaLink="false">https://medium.com/p/942e9b5df1d3</guid>
            <category><![CDATA[online-learning]]></category>
            <category><![CDATA[mooc]]></category>
            <category><![CDATA[online-education]]></category>
            <dc:creator><![CDATA[Yahia El Gamal]]></dc:creator>
            <pubDate>Fri, 26 Jun 2015 12:46:13 GMT</pubDate>
            <atom:updated>2016-06-07T19:40:47.537Z</atom:updated>
            <content:encoded><![CDATA[<p>It was a happy moment when the first 2 MOOCs were announced. Artificial Intelligence and Machine Learning by two amazing instructors. The movement only grew louder. I was ecstatic. But now, I am losing faith.</p><p><strong>Disclaimer: Most of my experience is around CS-oriented, machine learning, and data science courses.</strong></p><p>MOOCs were a great idea. Really distributive, really novel. I completed many courses and enjoyed many more. After 3 years, I started to get frustrated from the way it is evolving. Here is why I am frustrated:</p><h4><strong>Many courses compromise towards popularity rather than value.</strong></h4><p>Many courses are very simplified versions of what they should be. For example, most data science courses in the Coursera specialization track are over simplified and they don’t qualify to call their graduates data scientists. I am not saying they are bad, they are really useful. But they fall short on their promises. Yet, they will inject a feeling of mastery that is not true. And to me this is fatal.</p><p>I think the problem here lies around the fear of having a harder class that will target smaller audience but will benefit them invaluably. Instead courses tend to be over simplified that while they will boost the confidence of the students, it can only be called introductory but some folks (I was one of them) might think they are on the bleeding edge.</p><p>The other side of the spectrum are much fewer courses that deliver amazing value (<a href="https://www.coursera.org/course/mmds">Mining Massive Data Sets</a> is a great example, <a href="https://www.coursera.org/course/pgm">Probabilistic Graphical Models</a> is another), but because they aren’t necessarily easy, the fulfillment of the false feeling of mastery is gone.</p><p>The courses I really enjoyed and benefitted from are on the latter side. For this I think it would be more useful if we change our behavior towards some courses. For example:</p><ol><li><strong>Cover a wider spectrum of levels (introductory to advanced).</strong></li><li><strong>Make sure that students do not get fooled by a false feeling of mastery.</strong></li><li><strong>Optimize for value rather than hype.</strong></li><li><strong>Embrace a culture that gives credit to immersive courses that try to deliver courses of the same quality and advancement of their counterparts in the respecting institutes (that’s the promise of MOOCs after all).</strong></li></ol><p>This is quite important especially with the whole verification-based approaches that shows how completing a course is supposed to be used as a strong signal of competency.</p><p>We must avoid lying to ourselves and to the world. Some courses don’t deserve certifications and having certifications for them is “misleadingly” adding value that doesn’t exist and will, again, increase our false feeling of mastery. I am afraid that this will discourage students to look for more knowledge-rich courses and settle for easy, over-hyped courses.</p><blockquote>If you liked this piece please recommend and share it below!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=942e9b5df1d3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-higher-education-revolution/losing-faith-in-moocs-942e9b5df1d3">Losing Faith in MOOCs</a> was originally published in <a href="https://medium.com/the-higher-education-revolution">The Higher Education Revolution</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dating a Startup]]></title>
            <link>https://medium.com/@yahiaelgamal/dating-a-startup-cf5affa96155?source=rss-7dcf53259653------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf5affa96155</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[romance]]></category>
            <dc:creator><![CDATA[Yahia El Gamal]]></dc:creator>
            <pubDate>Sat, 26 Jul 2014 13:19:31 GMT</pubDate>
            <atom:updated>2017-11-24T14:44:36.968Z</atom:updated>
            <content:encoded><![CDATA[<p>In the middle of the night, I thought about the two things that keep most men and women awake at night, namely work and relationships. At this moment, I remembered how many people said that working (and especially at a startup) is like a relation, and sometimes a pretty consuming one. Then I thought of my ex-es (the startups, not the other ones ;)).</p><p>It always starts with mutual admiration. You will like her (without loss of generality, her refers to the startup). And as usual, when you get the goosebumps and butterflies, you try to impress her. Let’s assume you know a friend of her (an acquittance, an early employee, ..etc.). S/he sets a meeting for you (in the form of a casual chat with the big one there). You flirt, she accepts the flirtation. And probably if she really likes you, she will flirt back. “Oops, I did it again” said Cupid ;).</p><p>So you both like each other from the casual setup. One of you will try to setup a real date (in the form of an interview). Now the stakes are high, both of you want to impress the other. You prepare your A game, and she will too. It will start very similar to the first flirtation meeting, but this one will escalate really quickly. You will start to know her much better (if she feels comfortable around you), you also need to give her something too. Remember, you are probably starting a relation, it is a two-way road. So you start expressing yourself, in a way that impresses her (don’t worry, she’s not telling you her flaws as well). Right now, you should feel a connection, if you haven’t felt it that’s a bit of a red flag and don’t take any decision quickly.</p><p>Let’s assume you felt the connection, and she did as well. You will probably want to meet again. As of many relationships, there is someone who’s always insecure, doubtful, and needs to calculate his/her steps very carefully. Usually the startup is that one (if you are thinking of working in a startup, I really hope that you are not insecure nor doubtful). So you setup another date, some startups will prefer a hands-on (no pun intended, seriously) date, to make sure that you fit-in and can absorb her. This hands-on can be in the form of a small project to work with the team or solving a problem they are currently facing (maybe a made-up problem, but this serves the purpose). Others will continue the dating game a bit longer, they will go out once, twice, thrice and maybe more. Bear with it, you should have fun in those dates (they are dates after all, and you’re probably getting free coffee). Remember, “If she’s amazing, she won’t be easy. If she’s easy she won’t be amazing. If she’s worth it you won’t give up. If you give up, you’re not worthy” — Bob Marley.</p><p>Let’s hope everything went well. You both showed commitment and passion. You think you can pull it through. Then, and unlike any other relation, she’s the one who’s proposing!</p><p>It’s a total different level in your relation. Different dynamics, different feelings. Teen-like love is over. No more crushes. The actual story has just begun.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf5affa96155" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>