eg"><figcaption>Image by author</figcaption></figure><p id="d4f2">The modification of the pie chart leads to the donut chart. The size and the thickness of the donut can be manipulated by controling the x argument of the aesthetics of <code>ggplot()</code>. <b><i>Make sure the value of the x argument lies between the xlim range.</i></b></p><figure id="091b"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*l6p77L1eJThT8uGh59hqlA.jpeg"><figcaption>Image by author</figcaption></figure><h1 id="9b96">Bullseye chart</h1><p id="eeb0">For creating a circular bar plot, set argument <code>stat=“identity”</code> in <code>geom_bar()</code> function. Make sure to arrange the bars in increasing order of length when going radially outwards. For converting the bar chart to circular orientation set argument <code>theta=“y”</code> in the <code>coord_polar()</code> function. If the color bars complete one complete round then the chart will resemble a bullseye, hence the name.</p><figure id="4a65"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*fus_pI2nCrAlsuEIzJEC1A.jpeg"><figcaption>Image by author</figcaption></figure><h1 id="8e63">Coxcomb chart</h1><p id="1ad7">Simply changing a single argument in the bullseye chart will lead to coxcomb chart. Instead of assigning <code>theta=“y”</code> if its changed to <code>theta=“x”</code> in the <code>coord_polar()</code> function, we get coxcomb chart.</p><figure id="ca4a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*CbMFt-hgkhHFFukUwHrbfw.jpeg"><figcaption>Image by author</figcaption></figure><h1 id="2d33">Spider charts</h1><p id="fb8f">Currently, there is no function in <code>ggplot2</code> package to create spider or radar charts. <code>ggradar</code> package is compatible witth <code>ggplot2</code> package to that can be used to create spider charts. In ggradar() function, as in ggplot() function, the aesthetics can be defined. Few important arguments required are:</p><p id="f206"><i>values.radar</i>: prints the minimum, mid, and maximum values of the circular grid lines.</p><p id="6107"><i>grid.min</i>: minimum value of the grid</p><p id="2812"><i>grid.mid</i>: middle value of the grid</p><p id="96a0"><i>grid.max</i>: maximum value of the grid</p><p id="6a70"><b>Pros</b>: easy to understand if all the variables have the same scales.</p><p id="b939"><b>Cons</b>: difficult to compare when the scales have different units, hard to interpret circular plots.</p><figure id="ea8d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*JhIeFct2vTRQQ-AyejbHbg.jpeg"><figcaption>Image by author</figcaption></figure><p id="b99e">The complete code for plotting all the charts.</p>
<figure id="be14">
<div>
<div>
<iframe class="gist-iframe" src="/gist/amalasi2418/651a93b3dc4f8259804ae31c0cd8702e.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><h1 id="64b9">Conclusion</h1><p id="9f57">So in this tutorial, we saw how to create pie charts, spider plots, coxcomb charts, and bullseye charts. Identified how the pie chart can easily be converted to other chart types except for the spider plot by changing a couple of arguments either in the aesthetics of <code>ggplot()</code> function or in <code>geom_bar()</code> function. We further discussed the pros and cons of using circular chart types (especially pie charts and spider plots, bein the popular ones) and saw that in general these charts are discouraged and their alternatives are used which are easy to understand and interpret.</p><p id="4f27">Further readings from this series or on visualizations using <code>ggplot2</code> package.</p><div id="d80b" class="link-block">
<a href="https://towardsdatascience.com/master-data-visualization-with-ggplot2-scatter-and-box-plots-2f0c14cf2b26">
<div>
<div>
<h2>Master data visualization with
Options
ggplot2: scatter and box plots</h2>
<div><h3>Your guide to data visualization using scatter and box plots with ggplot2 package in R</h3></div>
<div><p>towardsdatascience.com</p></div>
</div>
<div>
<div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*OIHwdtovQwZ2Mq6T)"></div>
</div>
</div>
</a>
</div><div id="93c1" class="link-block">
<a href="https://towardsdatascience.com/master-data-visualization-with-ggplot2-histograms-bar-and-density-plots-86c8290c9adc">
<div>
<div>
<h2>Master data visualization with ggplot2: histograms, bar, and density plots</h2>
<div><h3>Your guide on when and how to use histograms, bar, and density plots in R</h3></div>
<div><p>towardsdatascience.com</p></div>
</div>
<div>
<div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*jLQHxO3VV4HKAYv7)"></div>
</div>
</div>
</a>
</div><div id="abf8" class="link-block">
<a href="https://towardsdatascience.com/data-visualization-using-ggplot2-5-features-worth-knowing-c0447a760335">
<div>
<div>
<h2>Data visualization using ggplot2: 5 features worth knowing</h2>
<div><h3>Tips to be more efficient using ggplot2 package for dataviz</h3></div>
<div><p>towardsdatascience.com</p></div>
</div>
<div>
<div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*vaMPLP5GjeyCwRgR)"></div>
</div>
</div>
</a>
</div><div id="9910" class="link-block">
<a href="https://towardsdatascience.com/creating-your-own-color-palette-for-data-visualization-part-1-84df48954845">
<div>
<div>
<h2>Creating your own color palette for data visualization-Part 1</h2>
<div><h3>A comprehensive color guide to creating your personal color palettes for data visualization.</h3></div>
<div><p>towardsdatascience.com</p></div>
</div>
<div>
<div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*Jn5e-l8xWo3HVMzl)"></div>
</div>
</div>
</a>
</div><div id="8007" class="link-block">
<a href="https://towardsdatascience.com/creating-your-own-color-palette-for-data-visualization-part-2-7b02ebc31c19">
<div>
<div>
<h2>Creating your own color palette for data visualization-Part 2</h2>
<div><h3>Balancing the tone, hue, and saturation to generate the perfect color gradients.</h3></div>
<div><p>towardsdatascience.com</p></div>
</div>
<div>
<div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*4BRjCdZgp9Cd9_pf)"></div>
</div>
</div>
</a>
</div><p id="9d7f">References</p><ol><li><a href="https://www.kaggle.com/crawford/80-cereals">https://www.kaggle.com/crawford/80-cereals</a></li><li><a href="https://blog.scottlogic.com/2011/09/23/a-critique-of-radar-charts.html#chart2">https://blog.scottlogic.com/2011/09/23/a-critique-of-radar-charts.html#chart2</a></li><li><a href="https://www.data-to-viz.com/caveat/spider.html">https://www.data-to-viz.com/caveat/spider.html</a></li></ol><p id="078a">The link to the complete code is <a href="https://github.com/amalasi2418/Blog-post/tree/master/ggplot2%20tutorial%203">here</a>.</p><p id="73cd">You can connect with me on <a href="https://www.linkedin.com/in/abhinav-malasi/">LinkedIn</a> and <a href="https://twitter.com/malasi_abhinav">Twitter</a> to follow my data science and data visualization journey.</p></article></body>
Master Data Visualization with ggplot2: Pie Charts, Spider Plots, and Bar Plots
Your go-to guide on creating pie charts, spider plots, and circular bar plots in R
In the third part of the data visualization series with ggplot2, we will focus on circular plots. The list of the tutorials are as follows:
Scatter and box plots
Histograms, Bar, and Density plots
Circular plots (pie charts, spider plots, and bar plots)
theme(): create your own theme() for increased workflow
So, under circular visualizations, we will be covering on how to create the following charts:
Pie charts
Spider charts
Circular bar plots
Further, we will discuss the pros and cons of using these types of visualizations.
With great power comes great responsibility, use pie and spider charts wisely.
Data and packages
For creating visuals for circular plots, we will be using the breakfast cereal dataset from Kaggle. The dataset has 77 unique cereal types with 16 fields.
We will be creating two new variables: manufact (contains the count of different cereal manufacturers) and cereal_Bran_low (filtered nutrition data for selected Bran cereal brand with calorie value between 80 and 120).
In the third part of the series, as usual, we will be using ggplot2 and tidyverse which are the basic packages widely used. Apart from them, for plotting spider or radar plot, ggradar package will be used.
Pie charts
For creating Pie charts, we will be using the manufact variable. There is no defined function for creating Pie chart in ggplot2 package, although the base plotting in R has pie() function. In order for us to plot Pie charts using ggplot2, we will use geom_bar() and coord_polar() functions to create segments of a circle. coord_polar() function converts the cartesian coordinates to the polar coordinate system, this way it is easy to create circular plots. The x argument for the ggplot() aesthetics is assigned as x=“ ” and the theta argument is assigned y value in the coord_polar() function.
To convert a bar chart to a pie chart, set stat=“identity” in geom_bar() and fix width=1 .
Pros: useful when comparing few data points.
Cons: difficult to interpret for large datasets, hard to depict trends overtime
Image by author
The modification of the pie chart leads to the donut chart. The size and the thickness of the donut can be manipulated by controling the x argument of the aesthetics of ggplot(). Make sure the value of the x argument lies between the xlim range.
Image by author
Bullseye chart
For creating a circular bar plot, set argument stat=“identity” in geom_bar() function. Make sure to arrange the bars in increasing order of length when going radially outwards. For converting the bar chart to circular orientation set argument theta=“y” in the coord_polar() function. If the color bars complete one complete round then the chart will resemble a bullseye, hence the name.
Image by author
Coxcomb chart
Simply changing a single argument in the bullseye chart will lead to coxcomb chart. Instead of assigning theta=“y” if its changed to theta=“x” in the coord_polar() function, we get coxcomb chart.
Image by author
Spider charts
Currently, there is no function in ggplot2 package to create spider or radar charts. ggradar package is compatible witth ggplot2 package to that can be used to create spider charts. In ggradar() function, as in ggplot() function, the aesthetics can be defined. Few important arguments required are:
values.radar: prints the minimum, mid, and maximum values of the circular grid lines.
grid.min: minimum value of the grid
grid.mid: middle value of the grid
grid.max: maximum value of the grid
Pros: easy to understand if all the variables have the same scales.
Cons: difficult to compare when the scales have different units, hard to interpret circular plots.
Image by author
The complete code for plotting all the charts.
Conclusion
So in this tutorial, we saw how to create pie charts, spider plots, coxcomb charts, and bullseye charts. Identified how the pie chart can easily be converted to other chart types except for the spider plot by changing a couple of arguments either in the aesthetics of ggplot() function or in geom_bar() function. We further discussed the pros and cons of using circular chart types (especially pie charts and spider plots, bein the popular ones) and saw that in general these charts are discouraged and their alternatives are used which are easy to understand and interpret.
Further readings from this series or on visualizations using ggplot2 package.