Skip to content
R for the Rest of Us Logo

Add additional horizontal lines

This lesson is locked

Get access to all lessons in this course.

If the video is not playing correctly, you can watch it in a new window

Transcript

Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

We’ve arrived at the probably the most fun lesson in this part of the course which is about theming and making the table more pretty. We’ll start by adding more lines to distinguish our summaries from the rest.

bind_rows(penguin_counts_wider, maximum_summary, total_summary) |> 
  mutate(island = paste('Island: ', island)) |> 
  arrange(island, year) |> 
  as_grouped_data(groups = 'island') |> 
  as_flextable(hide_grouplabel = TRUE) |> 
  set_header_labels(
    island = 'Island',
    year = '',
    Adelie_female = 'Female',
    Adelie_male = 'Male',
    Chinstrap_female = 'Female',
    Chinstrap_male = 'Male',
    Gentoo_female = 'Female',
    Gentoo_male = 'Male'
  ) |> 
  add_header_row(
    values = c('', 'Adelie', 'Chinstrap', 'Gentoo'),
    colwidths = c(1, 2, 2, 2)
  ) |> 
  add_header_lines(
    values = c('Penguins in the Palmer Archipelago', 'Data is courtesy of the {palmerpenguins} R package')
  ) |> 
  align(i = 3, align = 'center', part = 'header') |> 
  colformat_num(i = ~ (is.na(island)), na_str = '-') |> 
  align(
    i = ~ (year %in% 2007:2009),
    j = 'year',
    align = 'right'
  ) |> 
  hline(i = ~ (!is.na(island) | year %in% c('2009', 'Total'))) |> 
  autofit()

Your Turn

Structure your table by adding additional horizontal lines. More specifically, add horizontal lines after each continent label and before and after the block of maximum and average values. Your table should look like this:

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Pending approval

How to use : lead under hline " lead(country == 'Maximum', 2, default = FALSE) " Any documentation for reference ?

David Keyes

David Keyes Founder

February 1, 2024

Yes, check out the documentation here!