Table and Figure
- All figures and tables used in the internal report, papers, and presentations should be generated inside an R markdown file stored in
report/ folder.
- R markdown files to generate figures and tables should be knit to an html, because figures and tables are not nicely located in a pdf format.
- Weekly reports for the internal discussion should be stored in
report/report_weekly/ folder and named in %Y%m%d_xxxxx.Rmd format, such as 20210228_estimate_demand.Rmd. In xxxx, put some comments that nicely explains the topic.
- Other reports that are occasionally created should be also stored in
report/ folder.
- Inside an R markdown file, a path is evaluated relative to the location of the file. Therefore, in general, the location of the R markdown file matters. However, as we use
here::here function, we can evaluate any path as the relative path to the project root folder. This make the location of markdown files flexible.
- We need to generate figures and tables in a way we can use them in the internal report, papers, and presentations.
- Make sure that the information in the set of figures and tables used in the draft is the subset of information of the set of figures and tables generated in the report for the internal discussion. Never make a figure and table only appear in the draft without generating, analyzing, and discussing with the report.
- We export the figures and tables to files only when we start working on the draft. While discussing the results with the report, do not export any figure or table, because it messes up the figure and table folder.
- When exporting figures and tables to
figuretable folder, make a subfolder that has the same name with the reporting Rmd file. For example, if the reporting Rmd file is report/anayze_data.Rmd, then make a folder figuretable/analyze_data/ and export figure and table files into this subfolder. By doing so, we can easily find the report generating a specific figure and table in the draft. Moreover, it is easier to erase unused figures and tables.
- For tables, we need to prepare an environment where the same table can be easily and flexibly exported to HTML for internal reporting and to LaTeX for external papers.
- Some items such as the titles and notes of a table and a figure should be specified in the importing documents. Therefore, when generating tables to LaTeX, it should be exported as
tabular rather than table.
- I usually recommend calling a method in a package by explicitly specifying the package name like
dplyr::mutate. However, packages for table and figure, kableExtra, modelsummay, and ggplot2 are exceptions. We load them at the beginning of the code as library(kableExtra), library(modelsummary), library(ggplot2).
- First, these methods are hardly called inside a parallel loop. Therefore, we will not have to pass these libraries to distributed jobs.
- Second, specifying
ggplot2::aes and so on can be bothering.
- Third, for some reason, calling
modelsumary method in modelsummary package in the explicit form modelsummary::modelsummary does not work, even though other methods of modelsusummary can be called in the explicit form.
- Here are example Rmd file and its html output:
report/make_table_figure.Rmd
make_table_figure.Rmd
report/make_table_figure.html
make_table_figure.html
Table
- There are many packages to generate tables in HTML and latex. Currently, I recommend using
kableExtra::kbl`` for manually formatted tables and modelsummary::modelsummay` for regression tables.