Coordinate systems in ggplot2

Data Visualisation with R

Pie or donut charts with coord_polar()

  • The default coordinate system is the Cartesian coordinate system.
  • But you can change this to a polar coordinate system like below.
penguins %>% 
  group_by(species, sex, year) %>% 
  tally() %>% 
  ggplot(aes(sex, n, fill = species, group = year)) +
  geom_col(color = "black", position = "fill") +
  coord_polar("y")

Other coordinate systems

  • coord_cartesian() for Cartesian coordinate systems (default)
  • coord_flip() to flip the x and y
  • coord_fixed() to use a fixed aspect ratio
  • coord_equal() is essentially coord_fixed(ratio = 1)
  • coord_trans() to transform the coordinate after the statistical transformation
  • coord_map() to use projection based on mapproj