# values can be manually entered, some headlines are provided by default
headline(10, 8)
headline(8, 10)
headline(1:3, 3:1)
# most likely you'll edit the headline by hand
headline(
x = 10,
y = 8,
headline = "There was a ${delta} {trend} vs last year"
)
# you can also adjust the phrasing of higher/lower values
headline(
x = 10,
y = 8,
headline = "Group A was {trend} by {delta_p}%.",
trend_phrases = trend_terms(more = "higher", less = "lower")
)
# a phrase about the comparion can be edited by providing glue syntax
# 'c' = the 'compare' value, 'r' = 'reference'
headline(10, 8, orig_values = "{x} to {y} people")
# you can also add phrases for when the difference = 1 or not
headline(
x = 10,
y = 8,
plural_phrases = list(
were = plural_phrasing(single = "was", multi = "were"),
people = plural_phrasing(single = "person", multi = "people")
),
headline = "there {were} {delta} {people}"
)
# you can also adjust the rounding, the default is 1
headline(0.1234, 0.4321)
headline(0.1234, 0.4321, n_decimal = 3)
# or use a multiplier
headline(0.1234, 0.4321, multiplier = 100)
# there are many components you can assemble
headline(
x = 16,
y = 8,
headline = "there was {article_delta_p}% {trend}, \\
{add_article(trend)} of {delta} ({orig_values})"
)
# compare_conditions() produces a one-row data frame that can be
# passed to headline_list()
pixar_films |>
compare_conditions(
x = (rating == "G"),
y = (rating == "PG"),
rotten_tomatoes
) |>
headline_list(
headline = "On average, G-rated films score {delta} points {trend} than \\
PG films on Rotten Tomatoes",
trend_phrases = trend_terms(more = "higher", less = "lower")
)
# if you have more than 2 list items, you can specify them by name
list(
x = 1,
y = 2,
z = 3
) |>
headline_list(
x = x,
y = z
)
Run the code above in your browser using DataLab