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.
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')
Maps x to angle and y to radius. Useful for rose charts and radar-like displays.
p |> coord_polar()
pc |> coord_polar(innerRadius = 0.4)
pc |> coord_polar(startAngle = -pi / 2, endAngle = pi / 2)
Maps data values to angular extent. Used for pie and donut charts.
pc |>
transform('stackY') |>
coord_theta()
pc |>
transform('stackY') |>
coord_theta(innerRadius = 0.5)
Maps y to the radial direction. Suitable for radial bar charts.
pc |> coord_radial()
pc |> coord_radial(innerRadius = 0.3)
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')
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)
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()
Swap x and y axes, equivalent to ggplot2’s coord_flip(). This is a
coordinate transform, not a type.
p |> coord_transpose()
g2(iris, position = names(iris)[-5], color = ~ Species) |>
coord_parallel() |>
coord_transpose()