Open pedrohbraga opened 2 months ago
hello
It does not replace content with ----
but defines a tiny font size that give you the feeling it is ----
.
For PDF and given the content of your table, I would instead use a layout defined to "autofit" and not a fixed one.
---
title: "Untitled"
format: pdf
---
```{r include=FALSE}
library(dplyr)
library(magrittr)
library(flextable)
library(scales)
mpd.CFI.CHet.bS.gam.model_summaries <- structure(list(Scale = c(
"Global", "Global", "Global", "Global",
"Global", "Global", "Global", "Global", "Hemispheric", "Hemispheric",
"Hemispheric", "Hemispheric", "Hemispheric", "Hemispheric", "Hemispheric",
"Hemispheric", "Realm", "Realm", "Realm", "Realm", "Realm", "Realm",
"Realm", "Realm", "Biome", "Biome", "Biome", "Biome", "Biome",
"Biome", "Biome", "Biome"
), Taxon = c(
"Amphibians", "Amphibians",
"Birds", "Birds", "Mammals", "Mammals", "Squamates", "Squamates",
"Amphibians", "Amphibians", "Birds", "Birds", "Mammals", "Mammals",
"Squamates", "Squamates", "Amphibians", "Amphibians", "Birds",
"Birds", "Mammals", "Mammals", "Squamates", "Squamates", "Amphibians",
"Amphibians", "Birds", "Birds", "Mammals", "Mammals", "Squamates",
"Squamates"
), Response = c(
"MPD", "MPD", "MPD", "MPD", "MPD",
"MPD", "MPD", "MPD", "MPD", "MPD", "MPD", "MPD", "MPD", "MPD",
"MPD", "MPD", "MPD", "MPD", "MPD", "MPD", "MPD", "MPD", "MPD",
"MPD", "MPD", "MPD", "MPD", "MPD", "MPD", "MPD", "MPD", "MPD"
), Predictors = c(
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)",
"s(Clim. Freq.) + s(Clim. Het.)", "s(Clim. Freq.) + s(Clim. Het.)"
), Smooth.basis = c(
"Thin-plate splines", "Thin-plate splines",
"Thin-plate splines", "Thin-plate splines", "Thin-plate splines",
"Thin-plate splines", "Thin-plate splines", "Thin-plate splines",
"Thin-plate splines", "Thin-plate splines", "Thin-plate splines",
"Thin-plate splines", "Thin-plate splines", "Thin-plate splines",
"Thin-plate splines", "Thin-plate splines", "Thin-plate splines",
"Thin-plate splines", "Thin-plate splines", "Thin-plate splines",
"Thin-plate splines", "Thin-plate splines", "Thin-plate splines",
"Thin-plate splines", "Thin-plate splines", "Thin-plate splines",
"Thin-plate splines", "Thin-plate splines", "Thin-plate splines",
"Thin-plate splines", "Thin-plate splines", "Thin-plate splines"
), Adj..R.2 = c(
0.175, 0.175, 0.077, 0.077, 0.053, 0.053, 0.295,
0.295, 0.098, 0.098, 0.079, 0.079, 0.045, 0.045, 0.154, 0.154,
0.037, 0.037, 0.076, 0.076, 0.065, 0.065, 0.148, 0.148, 0.132,
0.132, 0.074, 0.074, 0.016, 0.016, 0.089, 0.089
), dev.uniq.non.linear = c(
0.039,
0.039, 0.038, 0.038, 0.007, 0.007, 0.017, 0.017, 0.026, 0.026,
0.031, 0.031, 0.007, 0.007, 0.036, 0.036, 0.025, 0.025, 0.018,
0.018, 0.017, 0.017, 0.035, 0.035, 0.027, 0.027, 0.008, 0.008,
0.015, 0.015, 0.031, 0.031
), Predictor = c(
"s(CFI.bS)", "s(heterogeneity.meanEuclid)",
"s(CFI.bS)", "s(heterogeneity.meanEuclid)", "s(CFI.bS)", "s(heterogeneity.meanEuclid)",
"s(CFI.bS)", "s(heterogeneity.meanEuclid)", "s(CFI.bS)", "s(heterogeneity.meanEuclid)",
"s(CFI.bS)", "s(heterogeneity.meanEuclid)", "s(CFI.bS)", "s(heterogeneity.meanEuclid)",
"s(CFI.bS)", "s(heterogeneity.meanEuclid)", "s(CFI.bS)", "s(heterogeneity.meanEuclid)",
"s(CFI.bS)", "s(heterogeneity.meanEuclid)", "s(CFI.bS)", "s(heterogeneity.meanEuclid)",
"s(CFI.bS)", "s(heterogeneity.meanEuclid)", "s(CFI.bS)", "s(heterogeneity.meanEuclid)",
"s(CFI.bS)", "s(heterogeneity.meanEuclid)", "s(CFI.bS)", "s(heterogeneity.meanEuclid)",
"s(CFI.bS)", "s(heterogeneity.meanEuclid)"
), edf = c(
8.94725336461062,
8.24474929940239, 8.94402808538318, 8.0433126490782, 8.5972718307536,
6.90985590548356, 8.96129511999248, 8.5986067320282, 8.96563886692967,
8.30961147988176, 8.98433079686555, 8.23076432847517, 8.90263880010934,
6.86404424849931, 8.97398220224686, 8.69075105939943, 8.95949377680743,
8.43700193247956, 8.97097220465126, 8.17551845665404, 8.94535035010068,
6.58312089445243, 8.97836907118496, 8.72640907751301, 8.8820397256442,
8.38989735222463, 8.92777933838305, 8.17965037889696, 8.44882219612362,
6.67862792516023, 8.94350263716568, 8.72142016558614
), Ref.df = c(
8.99918106400064,
8.84762420890626, 8.99907385783694, 8.76437213410865, 8.95428497695193,
8.02973917476159, 8.99955633527575, 8.95532361379465, 8.99964476828757,
8.87176481676359, 8.9999260146117, 8.84376427000312, 8.9971782037767,
7.99158455565594, 8.99979564755562, 8.97315094545215, 8.99951059845159,
8.91317490928138, 8.99974645533773, 8.82184062675737, 8.9991041994842,
7.7535736056498, 8.99985929333262, 8.97888578568561, 8.99581098178945,
8.89871654216935, 8.99841268199284, 8.8235135826169, 8.91354725246866,
7.8363113129187, 8.99902711654054, 8.97812146878775
), F = c(
4036.31513633459,
69.7911843367783, 1759.88065677894, 262.705849512569, 1443.42921525763,
194.454421113521, 8955.41928264452, 92.0348721761402, 2002.68924477316,
74.588383290832, 1780.02960506767, 322.540064864731, 1165.52780160569,
200.429583280523, 3622.23334399431, 223.319132967035, 622.826313416701,
123.844805888992, 1695.43875878549, 301.77693780504, 1757.59584121885,
203.782496099787, 3445.81563957982, 222.04847289181, 2850.33857052798,
108.262471571175, 1616.33541454028, 449.583131620976, 343.437567443098,
98.3637516856449, 1751.09643636829, 340.923735307398
), p.value = c(
0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
)), class = "data.frame", row.names = c(
NA,
-32L
))
ft <- mpd.CFI.CHet.bS.gam.model_summaries %>%
mutate(p.value = ifelse(p.value <= 0.0001, 0.001, 0)) %>%
group_by(Scale, Taxon, Predictor) %>%
mutate("signif" = NA) %>%
dplyr::select(
-c(
"Response",
"Predictors",
"Smooth.basis"
)
) %>%
flextable() %>%
merge_v(1:4) %>%
valign(valign = "top") %>%
add_header_lines(
values = "Thin-plate regression splines with formula: \nMPD ~ s(Clim. Freq.) + s(Clim. Het.)") %>%
bold(~ `p.value` <= 0.001, "p.value") %>%
theme_vanilla() %>%
colformat_double(j = c("edf", "Ref.df", "F", "dev.uniq.non.linear"), digits = 3) %>%
set_header_labels(
Scale = "Geographical Scale",
Adj..R.2 = "Total Adj. R2",
dev.uniq.non.linear = "Non-linear Adj. R2",
edf = "edf", Ref.df = "df", p.value = "p-value", signif = "") %>%
align(j = "signif", align = "left") %>%
bold(j = "signif", bold = TRUE) %>%
add_footer_lines(values = c(
"Signif. codes: 0 <= '***' < 0.001 < '**' < 0.01 < '*' < 0.05 < '.' < 0.1 < '' < 1"
)) %>%
flextable::fontsize(size = 8, part = "all") %>%
font(fontname = "Times New Roman", part = "all") %>%
set_table_properties(layout = "autofit")
ft
<img width="539" alt="Capture d’écran 2024-08-27 à 19 02 33" src="https://github.com/user-attachments/assets/2f50b75f-d864-4ad5-b415-9f0824d885e9">
Thank you for your response, @davidgohel! I understand your recommendation and will implement it!
I have an additional issue that I have been experiencing and observed in your output as well. The repeating header appears to overlap the content of tables split across pages, as in the example you pasted above. Would you have a recommendation on what I could do to fix this issue?
Here are a few examples of it happening. Note that it also messes up with the cases that are merged (using merge_v()
).
Here, for instance, what should be "Global" in the first row, has disappeared, probably due to this issue.
This can be reproduced with the same code you sent me, but please let me know if you would like some logs or specific files.
I have been trying to use
fit_to_width()
to produce tables with Quarto that fit a specific width within the page of the PDF. Unfortunately,autofit()
has not helped, andfit_to_width()
has not worked as intended. Whenever I use it, it replaces the table content with some placeholder text.Please find the code and the issue below:
Outcome: