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
Add your own ggplot
This lesson is locked
This lesson is called Add your own ggplot, part of the Making Beautiful Tables with R course. This lesson is called Add your own ggplot, part of the Making Beautiful Tables with R 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.
Let’s redo our own density plots.
single_species_weights <- penguin_mass$body_masses[[1]]
gg_density_plot <- function(weights) {
ggplot() +
stat_density(aes(x = weights), fill = 'dodgerblue4', col = 'grey20') +
coord_cartesian(xlim = range(penguins$body_mass_g)) +
theme_void()
}
list_of_ggplots <- map(penguin_mass$body_masses, gg_density_plot)
penguin_mass |>
flextable() |>
compose(
j = 'body_masses',
value = as_paragraph(
gg_chunk(
value = list_of_ggplots,
width = 3,
height = 1
)
)
)
gg_density_box_plot <- function(weights) {
ggplot(mapping = aes(x = weights)) +
stat_density(fill = 'dodgerblue4', col = 'grey20') +
geom_boxplot(width = 0.0005, position = position_nudge(y = -0.0005)) +
coord_cartesian(xlim = range(penguins$body_mass_g)) +
theme_void()
}
list_of_ggplots <- map(penguin_mass$body_masses, gg_density_box_plot)
penguin_mass |>
flextable() |>
compose(
j = 'body_masses',
value = as_paragraph(
gg_chunk(
value = list_of_ggplots,
width = 3,
height = 1
)
)
)
Your Turn
Redo the table from the previous exercise but use ggplot to draw the sparklines. This time, also add small dots at beginning and end of each sparkline.
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.