autoNumCaptions: An R package for auto-numbering html and markdown figures ================ Keaton Stagaman 6/25/2019
# install.packages("devtools")
devtools::install_github("kstagaman/autoNumCaptions")
When generating HTML or Markdown files using knitr
, utilizing the
caption
argument does not auto-number the figures or tables (as it
does when producing a PDF through LaTeX). This package allows one to add
auto-numbered captions directly to plots, ggplots, and tables.
Furthermore, because captions are not automattically wrapped to fit in
the plot space (ggplot
doesn’t wrap caption text), these functions
wrap the text to a length (in columns) that can be specified by the
user.
my.theme <- theme_update(plot.caption = element_text(hjust = 0, vjust = 1, size = 10))
ggplot(df1, aes(x = X, y = Y)) +
geom_point() +
gg_figure_caption(caption = "This figure demonstrates how to add a caption to a ggplot")
plot(
df1$X,
df1$Y,
sub = figure.caption("This figure demonstrates how to add a caption to a base plot")
)
ggplot(df1, aes(x = X, y = Y)) +
geom_point() +
gg_figure_caption(
caption = "This figure demonstrates how to add a caption to a supplemental ggplot",
supplemental = TRUE
)
ggplot(df1, aes(x = X, y = Y)) +
geom_point() +
gg_figure_caption(
caption = "This figure demonstrates how to add a caption to a supplemental ggplot and use \"S\" in front of the number instead of \"Supplemental\" in front of \"Figure\"",
supplemental = TRUE,
s.numbers = TRUE
)
kable(
df2,
caption = table.caption("This table demonstrates how to add a caption to a kable table")
) %>% kable_styling(font_size = 12, bootstrap_options = "striped", full_width = T)
Table 1. This table demonstrates how to add a caption to a kable table
A
B
C
D
E
F
G
H
red
1.3710
TRUE
0
North
3.1416
1.0476
4
green
\-0.5647
FALSE
5
South
9.8696
0.8267
5
blue
0.3631
TRUE
10
West
36.4622
0.4278
7
kable(
df2,
caption = supp.tbl.caption(
"This table demonstrates how to add a caption to a supplemental kable table"
)
) %>% kable_styling(font_size = 12, bootstrap_options = "striped")
Supplemental Table 1. This table demonstrates how to add a caption to a
supplemental kable table
A
B
C
D
E
F
G
H
red
1.3710
TRUE
0
North
3.1416
1.0476
4
green
\-0.5647
FALSE
5
South
9.8696
0.8267
5
blue
0.3631
TRUE
10
West
36.4622
0.4278
7
kable(
df2,
caption = supp.tbl.caption(
"This table demonstrates how to add a caption to a supplemental kable table and use \"S\" in front of the number instead of \"Supplemental\" in front of \"Table\"",
s.numbers = TRUE
)
) %>% kable_styling(font_size = 12, bootstrap_options = "striped")
Table S2. This table demonstrates how to add a caption to a supplemental
kable table and use “S” in front of the number instead of “Supplemental”
in front of “Table”
A
B
C
D
E
F
G
H
red
1.3710
TRUE
0
North
3.1416
1.0476
4
green
\-0.5647
FALSE
5
South
9.8696
0.8267
5
blue
0.3631
TRUE
10
West
36.4622
0.4278
7
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.