Exercise

Pie charts

The coord_polar() function converts a planar x-y Cartesian plot to polar coordinates. This can be useful if you are producing pie charts.

We can imagine two forms for pie charts - the typical filled circle, or a colored ring.

Typical pie charts omit all of the non-data ink, which we saw in the themes chapter of the last course. Pie charts are not really better than stacked bar charts, but we'll come back to this point in the next chapter.

A bar plot using mtcars of the number of cylinders (as a factor), fcyl, is shown in the console.

Instructions 1/2

undefined XP
  • 1
    • Run the code to see the stacked bar plot.
    • Add (+) a polar coordinate system, mapping the angle to the y variable by setting theta to "y".
  • 2
    • Reduce the width of the bars to 0.1.
    • Make it a ring plot by adding a continuous x scale with limits from 0.5 to 1.5.