Skip to content

Commit

Permalink
Fix kable duplicating table headings
Browse files Browse the repository at this point in the history
  • Loading branch information
ismayc committed Dec 6, 2024
1 parent 5f3fb57 commit f2bd14d
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 67 deletions.
10 changes: 5 additions & 5 deletions 02-visualization.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ In February 2006, a Swedish physician and data advocate named Hans Rosling gave
```{r gapminder-2007, echo=FALSE, purl=FALSE}
gapminder_2007 %>%
head(3) %>%
kable(
kbl(
digits = 2,
caption = "Gapminder 2007 Data: First 3 of 142 countries" # ,
) %>%
Expand Down Expand Up @@ -166,7 +166,7 @@ tibble(
aes = c("x", "y", "size", "color"),
geom = c("point", "point", "point", "point")
) %>%
kable(
kbl(
caption = "Summary of the grammar of graphics for this plot",
booktabs = TRUE,
linesep = ""
Expand Down Expand Up @@ -881,7 +881,7 @@ Observe in Figure \@ref(fig:flightsbar) that United Airlines (UA), JetBlue Airwa
flights_counted <- flights %>%
group_by(carrier) %>%
summarize(number = n())
kable(flights_counted,
kbl(flights_counted,
digits = 3,
caption = "Number of flights pre-counted for each carrier",
booktabs = TRUE,
Expand Down Expand Up @@ -1151,7 +1151,7 @@ if (is_latex_output()) {
summary_table_ch2 %>%
# Weird tick marks show up in PDF:
mutate(`Geometric object` = str_replace_all(`Geometric object`, "`", "")) %>%
kable(
kbl(
caption = "Summary of Five Named Graphs",
booktabs = TRUE,
format = "latex",
Expand All @@ -1163,7 +1163,7 @@ if (is_latex_output()) {
column_spec(5, width = "1.6in")
} else {
summary_table_ch2 %>%
kable(
kbl(
caption = "Summary of Five Named Graphs",
booktabs = TRUE,
format = "html"
Expand Down
4 changes: 2 additions & 2 deletions 03-wrangling.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ Let's take a look at only the `dep_delay`, `arr_delay`, and the resulting `gain`
flights %>%
select(dep_delay, arr_delay, gain) %>%
slice(1:5) %>%
kable(
kbl(
caption = "First five rows of departure/arrival delay and gain variables"
) %>%
kable_styling(position = "center", latex_options = "hold_position")
Expand Down Expand Up @@ -872,7 +872,7 @@ if (is_latex_output()) {
Verb = str_replace_all(Verb, "`", ""),
`Data wrangling operation` = str_replace_all(`Data wrangling operation`, "`", ""),
) %>%
kable(
kbl(
caption = "Summary of data wrangling verbs",
booktabs = TRUE,
linesep = "",
Expand Down
6 changes: 3 additions & 3 deletions 04-tidy.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ stocks <- tibble(
) %>%
slice(1:2)
stocks %>%
kable(
kbl(
digits = 2,
caption = "Stock prices (non-tidy format)",
booktabs = TRUE,
Expand Down Expand Up @@ -253,7 +253,7 @@ stocks_tidy <- stocks %>%
values_to = "Stock Price"
)
stocks_tidy %>%
kable(
kbl(
digits = 2,
caption = "Stock prices (tidy format)",
booktabs = TRUE,
Expand All @@ -275,7 +275,7 @@ stocks <- tibble(
) %>%
slice(1:2)
stocks %>%
kable(
kbl(
digits = 2,
caption = "Example of tidy data" # ,
# booktabs = TRUE
Expand Down
20 changes: 10 additions & 10 deletions 05-regression.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ evals_ch5 %>%
```{r five-random-courses, echo=FALSE, purl=FALSE}
evals_ch5 %>%
sample_n(5) %>%
kable(
kbl(
digits = 3,
caption = "A random sample of 5 out of the 463 courses at UT Austin",
booktabs = TRUE,
Expand Down Expand Up @@ -429,7 +429,7 @@ evals_line <- score_model %>%
```
```{r regtable, echo=FALSE, purl=FALSE}
get_regression_table(score_model) %>%
kable(
kbl(
digits = 3,
caption = "Linear regression table",
booktabs = TRUE,
Expand Down Expand Up @@ -516,7 +516,7 @@ y_hat <- target_point$score_hat
resid <- target_point$residual
evals_ch5 %>%
slice(index) %>%
kable(
kbl(
digits = 4,
caption = "Data for the 21st course out of 463",
booktabs = TRUE,
Expand Down Expand Up @@ -694,7 +694,7 @@ gapminder2007 %>% sample_n(size = 5)
```{r model2-data-preview, echo=FALSE, purl=FALSE}
gapminder2007 %>%
sample_n(5) %>%
kable(
kbl(
digits = 3,
caption = "Random sample of 5 out of 142 countries",
booktabs = TRUE,
Expand Down Expand Up @@ -872,7 +872,7 @@ gapminder2007 %>%
group_by(continent) %>%
summarize(mean = mean(lifeExp)) %>%
mutate(`Difference versus Africa` = mean - mean_africa) %>%
kable(
kbl(
digits = 3,
caption = "Mean life expectancy by continent and relative differences from mean for Africa",
booktabs = TRUE,
Expand Down Expand Up @@ -916,7 +916,7 @@ lifeExp_model <- lm(lifeExp ~ continent, data = gapminder2007)
```
```{r catxplot4b, echo=FALSE, purl=FALSE}
get_regression_table(lifeExp_model) %>%
kable(
kbl(
digits = 3,
caption = "Linear regression table",
booktabs = TRUE,
Expand Down Expand Up @@ -1059,7 +1059,7 @@ regression_points
regression_points <- get_regression_points(lifeExp_model, ID = "country")
regression_points %>%
slice(1:10) %>%
kable(
kbl(
digits = 3,
caption = "Regression points (First 10 out of 142 countries)",
booktabs = TRUE,
Expand Down Expand Up @@ -1302,7 +1302,7 @@ get_regression_table(score_model)
```{r recall-table, echo=FALSE, purl=FALSE}
score_model <- lm(score ~ bty_avg, data = evals_ch5)
get_regression_table(score_model) %>%
kable(
kbl(
digits = 3,
caption = "Regression table",
booktabs = TRUE,
Expand Down Expand Up @@ -1341,7 +1341,7 @@ score_model %>%
lower_ci = conf_low,
upper_ci = conf_high
) %>%
kable(
kbl(
digits = 3,
caption = "Regression table using tidy() from broom package",
booktabs = TRUE,
Expand Down Expand Up @@ -1375,7 +1375,7 @@ score_model %>%
clean_names() %>%
select(-c("std_resid", "hat", "sigma", "cooksd", "std_resid")) %>%
slice(1:10) %>%
kable(
kbl(
digits = 3,
caption = "Regression points using augment() from broom package",
booktabs = TRUE,
Expand Down
34 changes: 17 additions & 17 deletions 06-multiple-regression.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ evals_ch6 %>% sample_n(size = 5)
```{r model4-data-preview, echo=FALSE, purl=FALSE}
evals_ch6 %>%
sample_n(5) %>%
kable(
kbl(
digits = 3,
caption = "A random sample of 5 out of the 463 courses at UT Austin",
booktabs = TRUE,
Expand Down Expand Up @@ -221,7 +221,7 @@ lifeExp_model <- lm(lifeExp ~ continent, data = gapminder2007)
# Get regression table and kable output
get_regression_table(lifeExp_model) %>%
kable(
kbl(
digits = 3,
caption = "Regression table for life expectancy as a function of continent",
booktabs = TRUE,
Expand Down Expand Up @@ -267,7 +267,7 @@ get_regression_table(score_model_interaction)
```{r regtable-interaction, echo=FALSE, purl=FALSE}
score_model_interaction <- lm(score ~ age * gender, data = evals_ch6)
get_regression_table(score_model_interaction) %>%
kable(
kbl(
digits = 3,
caption = "Regression table for interaction model",
booktabs = TRUE,
Expand Down Expand Up @@ -312,7 +312,7 @@ tibble(
Intercept = c(intercept_female, intercept_male),
`Slope for age` = c(slope_female, slope_male)
) %>%
kable(
kbl(
digits = 4,
caption = "Comparison of intercepts and slopes for interaction model",
booktabs = TRUE,
Expand Down Expand Up @@ -429,7 +429,7 @@ get_regression_table(score_model_parallel_slopes)
```{r regtable-parallel-slopes, echo=FALSE, purl=FALSE}
score_model_parallel_slopes <- lm(score ~ age + gender, data = evals_ch6)
get_regression_table(score_model_parallel_slopes) %>%
kable(
kbl(
digits = 3,
caption = "Regression table for parallel slopes model",
booktabs = TRUE,
Expand Down Expand Up @@ -469,7 +469,7 @@ tibble(
Intercept = c(intercept_female_parallel, intercept_male_parallel),
`Slope for age` = c(age_coef, age_coef)
) %>%
kable(
kbl(
digits = 4,
caption = "Comparison of intercepts and slope for parallel slopes model",
booktabs = TRUE,
Expand Down Expand Up @@ -595,7 +595,7 @@ regression_points
regression_points <- get_regression_points(score_model_interaction)
regression_points %>%
slice(1:10) %>%
kable(
kbl(
digits = 3,
caption = "Regression points (First 10 out of 463 courses)" # ,
# booktabs = TRUE
Expand Down Expand Up @@ -668,7 +668,7 @@ credit_ch6 %>% sample_n(size = 5)
```{r model3-data-preview, echo=FALSE, purl=FALSE}
credit_ch6 %>%
sample_n(5) %>%
kable(
kbl(
digits = 3,
caption = "Random sample of 5 credit card holders",
booktabs = TRUE,
Expand Down Expand Up @@ -720,7 +720,7 @@ credit_ch6 %>%
credit_ch6 %>%
select(debt, credit_limit, income) %>%
cor() %>%
kable(
kbl(
digits = 3,
caption = "Correlation coefficients between credit card debt, credit limit, and income",
booktabs = TRUE,
Expand Down Expand Up @@ -874,7 +874,7 @@ debt_model <- lm(debt ~ credit_limit + income, data = credit_ch6)
credit_line <- get_regression_table(debt_model) %>%
pull(estimate)
get_regression_table(debt_model) %>%
kable(
kbl(
digits = 3,
caption = "Multiple regression table",
booktabs = TRUE,
Expand Down Expand Up @@ -941,7 +941,7 @@ set.seed(76)
regression_points <- get_regression_points(debt_model)
regression_points %>%
slice(1:10) %>%
kable(
kbl(
digits = 3,
caption = "Regression points (First 10 credit card holders out of 400)",
booktabs = TRUE,
Expand Down Expand Up @@ -1062,7 +1062,7 @@ model_2_interaction <- lm(average_sat_math ~ perc_disadvan * size,
data = MA_schools
)
get_regression_table(model_2_interaction) %>%
kable(
kbl(
digits = 3,
caption = "Interaction model regression table",
booktabs = TRUE,
Expand All @@ -1083,7 +1083,7 @@ model_2_parallel_slopes <- lm(average_sat_math ~ perc_disadvan + size,
data = MA_schools
)
get_regression_table(model_2_parallel_slopes) %>%
kable(
kbl(
digits = 3,
caption = "Parallel slopes regression table",
booktabs = TRUE,
Expand Down Expand Up @@ -1178,7 +1178,7 @@ bind_rows(
variances_parallel_slopes
) %>%
select(model, var_y, var_y_hat, var_residual, r_squared) %>%
knitr::kable(
kbl(
digits = 3,
caption = "Comparing variances from interaction and parallel slopes models for MA school data",
booktabs = TRUE,
Expand All @@ -1205,7 +1205,7 @@ bind_rows(
variances_parallel_slopes
) %>%
select(model, var_y, var_y_hat, var_residual, r_squared) %>%
knitr::kable(
kbl(
digits = 3,
caption = "Comparing variances from interaction and parallel slopes models for UT Austin data",
booktabs = TRUE,
Expand Down Expand Up @@ -1244,7 +1244,7 @@ credit_ch6 %>%
select(debt, income) %>%
mutate(income = income * 1000) %>%
cor() %>%
kable(
kbl(
digits = 3,
caption = "Correlation between income (in dollars) and credit card debt",
booktabs = TRUE,
Expand Down Expand Up @@ -1274,7 +1274,7 @@ debt_model <- lm(debt ~ credit_limit + income, data = credit_ch6)
credit_line <- get_regression_table(debt_model) %>%
pull(estimate)
get_regression_table(debt_model) %>%
kable(
kbl(
digits = 3,
caption = "Multiple regression results",
booktabs = TRUE,
Expand Down
10 changes: 5 additions & 5 deletions 07-sampling.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ comparing_n_table <- virtual_prop %>%
rename(`Number of slots in shovel` = n, `Standard deviation of proportions red` = sd)
comparing_n_table %>%
kable(
kbl(
digits = 3,
caption = "Comparing standard deviations of proportions red for three different shovels",
booktabs = TRUE,
Expand Down Expand Up @@ -817,7 +817,7 @@ comparing_n_table <- virtual_prop %>%
rename(`Number of slots in shovel` = n, `Standard deviation of proportions red` = sd)
comparing_n_table %>%
kable(
kbl(
digits = 3,
caption = "Previously seen comparing standard deviations of proportions red for three different shovels",
booktabs = TRUE,
Expand Down Expand Up @@ -873,7 +873,7 @@ comparing_n_table <- virtual_prop %>%
rename(`Sample size (n)` = n, `Standard error of $\\widehat{p}$` = sd)
comparing_n_table %>%
kable(
kbl(
digits = 3,
caption = "Standard errors of the sample proportion based on sample sizes of 25, 50, and 100",
booktabs = TRUE,
Expand Down Expand Up @@ -985,7 +985,7 @@ comparing_n_table <- virtual_prop %>%
sample_frac(1)
comparing_n_table %>%
kable(
kbl(
digits = 3,
caption = "Standard errors of $\\widehat{p}$ based on n = 25, 50, 100",
booktabs = TRUE,
Expand Down Expand Up @@ -1177,7 +1177,7 @@ if (!file.exists("rds/sampling_scenarios.rds")) {
}
sampling_scenarios %>%
kable(
kbl(
caption = "\\label{tab:summarytable-ch8}Scenarios of sampling for inference",
booktabs = TRUE,
escape = FALSE,
Expand Down
Loading

0 comments on commit f2bd14d

Please sign in to comment.