## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.align = "center"
)

## ----warning=FALSE, message=FALSE---------------------------------------------
library(ggchord2)
library(ggplot2)
library(dplyr)

## -----------------------------------------------------------------------------
set.seed(123)
n <- 15
flows <- expand.grid(
  source = 1:n,
  target = 1:n
) |>
  filter(source < target) |>
  mutate(
    source = paste0("Category ", LETTERS[source]),
    target = paste0("Category ", LETTERS[target]),
    freq = rpois(((n^2 - n) / 2), 4)
  )

## -----------------------------------------------------------------------------
g <- ggplot(
  data = flows,
  mapping = aes(
    source = source,
    target = target,
    freq = freq
  )
) +
  geom_chord_arcs(
    mapping = aes(fill = source),
    alpha = 0.5
  ) +
  geom_chord_sectors(
    mapping = aes(fill = source),
    colour = "white",
    linewidth = 0.8
  ) +
  coord_fixed() +
  theme_void() +
  theme(legend.position = "none")

## -----------------------------------------------------------------------------
g +
  geom_chord_labels(
    mapping = aes(colour = source),
    size = 4
  )

## -----------------------------------------------------------------------------
g +
  geom_chord_labels(
    mapping = aes(colour = source),
    size = 4
  ) +
  scale_x_continuous(limits = c(-1.5, 1.5))

## -----------------------------------------------------------------------------
g +
  geom_chord_labels_perp(
    mapping = aes(colour = source),
    size = 4
  ) +
  scale_x_continuous(limits = c(-1.5, 1.5)) +
  scale_y_continuous(limits = c(-1.5, 1.5))

## -----------------------------------------------------------------------------
g +
  geom_chord_labels_curve(
    mapping = aes(colour = source),
    size = 4
  ) +
  scale_x_continuous(limits = c(-1.5, 1.5))

