Coordinates

library(gglite)

Coordinate systems control how the positional channels (x and y) are interpreted. Use helpers like coord_polar(), coord_theta(), coord_radial(), coord_helix(), and coord_parallel() to set the coordinate system.

1 Cartesian (default)

The default coordinate system. Typically you don’t need to specify it explicitly, but you can do so for clarity.

df = data.frame(x = c('A', 'B', 'C', 'D'), y = c(3, 7, 2, 5))
p  = g2(df, y ~ x)
pc = g2(df, y ~ x, color = ~ x)
p |> coord_('cartesian')

2 Polar

Maps x to angle and y to radius. Useful for rose charts and radar-like displays.

p |> coord_polar()

2.1 Polar with innerRadius (donut rose)

pc |> coord_polar(innerRadius = 0.4)

2.2 Polar with custom start/end angles

pc |> coord_polar(startAngle = -pi / 2, endAngle = pi / 2)

3 Theta

Maps data values to angular extent. Used for pie and donut charts.

pc |>
  transform('stackY') |>
  coord_theta()

3.1 Donut chart (theta with innerRadius)

pc |>
  transform('stackY') |>
  coord_theta(innerRadius = 0.5)

4 Radial

Maps y to the radial direction. Suitable for radial bar charts.

pc |> coord_radial()

4.1 Radial with innerRadius

pc |> coord_radial(innerRadius = 0.3)

5 Parallel

Maps multiple numeric variables to parallel axes. Use a position encoding (a character vector of column names) instead of x/y.

g2(iris, position = names(iris)[-5], color = ~ Species) |>
  canvas(padding = 30) |>
  coord_parallel() |>
  legend_color(position = 'bottom')

6 Radar

Displays data on radial axes emanating from a center point. A radar chart is a line or area chart in polar coordinates. Use long-format data with x (category), y (value), and color (series) encodings. All values should be on the same scale (e.g., 0–100).

df_radar = data.frame(
  item = rep(c('Design', 'Dev', 'Marketing', 'Sales', 'Support'), 2),
  score = c(80, 90, 65, 75, 85, 60, 70, 85, 80, 70),
  team = rep(c('A', 'B'), each = 5)
)
g2(df_radar, score ~ item, color = ~ team) |>
  mark_area() |> style_mark(fillOpacity = 0.5) |>
  mark_line() |> style_mark(lineWidth = 2) |>
  mark_point() |>
  coord_polar() |>
  scale_x(padding = 0.5, align = 0) |>
  scale_y(domainMin = 0, domainMax = 100) |>
  axis_y(grid = TRUE, title = FALSE)

7 Helix

Arranges data along a helix spiral. Works best with mark_interval().

df_helix = data.frame(x = paste0('D', 1:50), y = abs(sin(1:50 / 5)))
g2(df_helix, y ~ x, color = ~ y) |>
  coord_helix()

8 Transpose (coord_flip)

Swap x and y axes, equivalent to ggplot2’s coord_flip(). This is a coordinate transform, not a type.

p |> coord_transpose()

8.1 Transpose with parallel

g2(iris, position = names(iris)[-5], color = ~ Species) |>
  coord_parallel() |> 
  coord_transpose()