Creates a standalone ggplot2 table and overlays it onto a base plot using cowplot at specified coordinates.

df2gg_floating(
  df,
  gg_plt,
  x = 0.8,
  y = 0.8,
  w = 0.3,
  h = 0.2,
  colwidths = NULL,
  font_size = 10,
  col_labels = TRUE,
  col_lab_fontface = "bold",
  hline = TRUE,
  bg_fill = NULL
)

Arguments

df

(data.frame)
The data frame to render.

gg_plt

(ggplot2)
The main plot to overlay the table onto.

x

(numeric)
X-coordinate for the box anchor position (0 to 1).

y

(numeric)
Y-coordinate for the box anchor position (0 to 1).

w

(numeric)
Width of the annotation box (0 to 1).

h

(numeric)
Height of the annotation box (0 to 1).

colwidths

(numeric)
Numeric vector of relative column widths.

font_size

(numeric)
Base font size.

col_labels

(logical)
Whether to display column labels (header).

col_lab_fontface

(character)
String for the font face of column labels (e.g., "bold").

hline

(logical)
Whether to draw a horizontal line below the column labels.

bg_fill

(character)
Optional color string for the plot background.

Value

A cowplot object representing the combined plot and table.

Details

The original plots are stored in attr(result, "plotlist") as a named list (main and table) for downstream data extraction.

Examples

if (FALSE) { # \dontrun{

# 1. Create a base plot
p_base <- ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  theme_classic()

# 2. Create a mock summary table
mock_df <- data.frame(
  Statistic = c("N", "Median", "Mean"),
  Value = c("32", "19.2", "20.1")
)

# 3. Float the table on the plot
result <- df2gg_floating(
  df = mock_df,
  gg_plt = p_base,
  x = 0.75,
  y = 0.75,
  w = 0.35,
  h = 0.25,
  bg_fill = "white"
)

# 4. Extract the original plots and data
plist <- attr(result, "plotlist")
plist$main$data # original dataframe from the base plot
plist$table # the floating table ggplot object
} # }