CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Intermediate Data Visualization with ggplot2

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Run the code, view the plot, then update it
ggplot(mtcars, aes(x = 1, fill = fcyl)) +
  geom_bar()
  # Add a polar coordinate system
  
Modifier et exécuter le code