Get access to all lessons in this course.
- Get Data Into the Right Format to Create your First Table
- Use better column names and a title
- Align columns
- Use groups instead of repetitive columns
- Format your table's numbers
- Add summaries
- Add additional horizontal lines
- Add background colors
- Change the text appearance
- Change cell properties
- Export Your Tables
- Heat map columns
- Adding Charts with Flextable
- Add your own ggplot
- Case Study
Making Beautiful Tables with R
Adding Charts with Flextable
This lesson is locked
This lesson is called Adding Charts with Flextable, part of the Making Beautiful Tables with R course. This lesson is called Adding Charts with Flextable, part of the Making Beautiful Tables with R course.
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.
Sparklines are small lines that help you to find trends in the data really fast. By now, they’re one of the standard tricks in the table trade. Here's how to add one in a flextable.
counts_over_time <- penguin_counts |>
group_by(species, island, sex) |>
summarise(collected_data = list(n)) |>
ungroup()
counts_over_time |>
flextable() |>
compose(j = 'collected_data', value = as_paragraph(
plot_chunk(value = collected_data, type = 'line', col = 'dodgerblue4')
))
And here's how to add a boxplot to a table.
penguin_mass <- penguins |>
group_by(species) |>
summarise(body_masses = list(body_mass_g)) |>
ungroup()
penguin_mass |>
flextable() |>
compose(
j = 'body_masses',
value = as_paragraph(
plot_chunk(
value = body_masses,
type = 'dens',
col = 'dodgerblue4',
width = 3,
height = 1
)
)
)
Your Turn
Instead of turning columns into a heat map, add another column to your table that contains a sparkline depicting the life expectancy over time for each country. If you don’t want to create sparklines for the average and maximum rows, then use value = as_paragraph('')
in a second call to the compose()
function.
Hint: If you want, you can manually change the width of the sparkline column with width()
after autofit()
was called.
Your table should look like this:
You need to be signed-in to comment on this post. Login.