Skip to contents

Horizontal bar chart of nutrient values for a single food with optional SE error bars. Only nutrients with a non-NA point estimate are shown.

Usage

plot_composition(
  food,
  table,
  nutrients = NULL,
  se = TRUE,
  label_fn = function(x) gsub("_.*", "", x),
  title = NULL,
  subtitle = NULL,
  xlab = "Value per 100 g edible portion",
  match = c("fixed", "regex")
)

Arguments

food

Food name (substring) or exact food code.

table

IFCT table name (e.g. "amino_acids").

nutrients

Optional character vector of column-name substrings to include. NULL keeps all columns.

se

If TRUE (default), add SE error bars where available.

label_fn

Function applied to column names to produce axis labels.

title

Plot title. Defaults to the matched food name.

subtitle

Plot subtitle.

xlab

x-axis label.

match

One of "fixed" (default) or "regex".

Value

A ggplot2 object.

Examples

plot_composition("Bengal gram", table = "amino_acids")
#>  Retrieved 2 rows for 2 foods.
#>  Retrieved 2 rows for 2 foods.

plot_composition("Rice", table = "proximate", se = FALSE)
#>  Retrieved 6 rows for 6 foods.
#>  Retrieved 6 rows for 6 foods.