Skip to contents

Draws either a grouped bar chart of counts by time point (type = "plot") or a numeric text-table panel suitable for composing below the bar chart via patchwork (type = "table").

Usage

# S3 method for class 'hv_longitudinal'
plot(
  x,
  type = c("plot", "table"),
  position = "dodge",
  label_format = NULL,
  ...
)

Arguments

x

An hv_longitudinal object.

type

Which panel to produce: "plot" (default) or "table".

position

Bar position for type = "plot": "dodge" (default) or "stack".

label_format

Formatting function applied to count values for type = "table". NULL (default) auto-selects scales::comma when the scales package is installed, otherwise falls back to base::as.character. Pass identity to display counts without formatting.

...

Ignored; present for S3 consistency.

Value

A bare ggplot object.

See also

Examples

library(ggplot2)
dta <- sample_longitudinal_counts_data(n_patients = 300, seed = 42L)
lc  <- hv_longitudinal(dta)

# Bar chart
plot(lc, type = "plot") +
  scale_fill_manual(
    values = c(Patients = "steelblue", Measurements = "firebrick"),
    name   = NULL
  ) +
  labs(x = "Follow-up Window", y = "Count (n)") +
  hv_theme("poster")


# Text table panel
plot(lc, type = "table") +
  scale_colour_manual(
    values = c(Patients = "steelblue", Measurements = "firebrick"),
    guide  = "none"
  ) +
  hv_theme("poster")


# Compose with patchwork
# p_bar   <- plot(lc, type = "plot")   + <decorators>
# p_table <- plot(lc, type = "table")  + <decorators>
# p_bar / p_table + patchwork::plot_layout(heights = c(3, 1))