-
Notifications
You must be signed in to change notification settings - Fork 11
/
README.Rmd
724 lines (581 loc) · 29.1 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/",
out.width = "100%"
)
```
```{R,echo=FALSE,results='hide',message=FALSE,include=FALSE, eval=TRUE}
## Packages
pkgs <- c("knitr",
"tidyverse",
"dplyr",
"magrittr",
"countrycode",
"xtable")
## Install uninstalled packages
lapply(pkgs[!(pkgs %in% installed.packages())], install.packages)
## Load all packages to library
lapply(pkgs, library, character.only = TRUE)
```
# overviewR <img src='man/figures/logo.png' align="right" height="139" />
<!-- badges: start -->
[![R-CMD-check](https://github.com/cosimameyer/overviewR/workflows/R-CMD-check/badge.svg)](https://github.com/cosimameyer/overviewR/actions)
[![Codecov test coverage](https://codecov.io/gh/cosimameyer/overviewR/branch/master/graph/badge.svg)](https://app.codecov.io/gh/cosimameyer/overviewR?branch=master)
<!--
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/overviewR)](https://cran.r-project.org/package=overviewR)
[![license](https://img.shields.io/badge/license-GPL--3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html)
[![metacran downloads](https://cranlogs.r-pkg.org/badges/overviewR)](https://cran.r-project.org/package=overviewR)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![overviewR badge](https://img.shields.io/badge/overviewR-ready%20to%20use-brightgreen)](https://github.com/cosimameyer/overviewR)
[![R badge](https://img.shields.io/badge/Build%20with-♥%20and%20R-blue)](https://github.com/cosimameyer/overviewR)-->
<!-- [![Rdoc](https://www.rdocumentation.org/badges/version/overviewR)](https://www.rdocumentation.org/packages/overviewR) -->
<!-- [![cran checks](https://cranchecks.info/badges/summary/overviewR)](https://cran.r-project.org/web/checks/check_results_overviewR.html) -->
<!-- [![](https://cranlogs.r-pkg.org/badges/version/overviewR)](https://www.r-pkg.org/badges/version/overviewR) -->
<!-- [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) -->
<!-- [![Last-changedate](https://img.shields.io/badge/last%20change-`r gsub('-', '--', Sys.Date())`-green.svg)](/commits/master) -->
<!-- badges: end -->
[**You can access the CheatSheet for overviewR here**](https://github.com/cosimameyer/overviewR/blob/master/man/figures/CheatSheet_overviewR.pdf)
The goal of overviewR is to make it easy to get an overview of a data set by displaying relevant sample information. At the moment, there are the following functions:
- `overview_tab` generates a tabular overview of the sample. The general sample plots a two-column table that provides information on an id in the left column and a the time frame on the right column.
- `overview_crosstab` generates a cross table. The conditional column allows to disaggregate the overview table by specifying two conditions, hence resulting a 2x2 table. This way, it is easy to visualize the time and scope conditions as well as theoretical assumptions with examples from the data set.
- `overview_latex` converts the output of both `overview_tab` and `overview_crosstab` into LaTeX code and/or directly into a .tex file.
- `overview_plot` is an alternative to visualize the sample (a way to present results from `overview_tab`)
- `overview_crossplot` is an alternative to visualize a cross table (a way to present results from `overview_crosstab`)
- `overview_heat` plots a heat map of your time line
- `overview_na` plots an overview of missing values by variable (both by row and by column)
- `overview_overlap` plots comparison plots (bar graph and Venn diagram) to compare to data frames
The plots can be saved using the `ggsave()` command. The output of `overview_tab` and `overview_crosstab` are also compatible with other packages such as [```xtable```](https://CRAN.R-project.org/package=xtable), [```flextable```](https://CRAN.R-project.org/package=flextable), or [`knitr`](https://bookdown.org/yihui/rmarkdown-cookbook/kable.html).
We present a short step-by-step guide as well as the functions in more detail below.
## Installation
A stable version of `overviewR` can be directly accessed on CRAN:
```{r, eval=FALSE}
install.packages("overviewR", force = TRUE)
```
To install the latest development version of `overviewR` directly from [GitHub](https://github.com/cosimameyer/overviewR) use:
```{r, message=FALSE, warning=FALSE, results = "hide", eval=FALSE}
library(devtools) # Tools to Make Developing R Packages Easier # Tools to Make Developing R Packages Easier
devtools::install_github("cosimameyer/overviewR")
```
## Example
First, load the package.
```{r, include = FALSE, eval = FALSE}
install.packages("overviewR")
```
```{r, message=FALSE, warning=FALSE}
library(overviewR) # Easily Extracting Information About Your Data # Easily Extracting Information About Your Data
```
The following examples use a toy data set (`toydata`) that comes with the package. This data contains artificially generated information in a cross-sectional format on 5 countries, covering the period 1990-1999.
```{r}
data(toydata)
head(toydata)
```
<!-- ``` -->
<!-- ccode year month gdp population -->
<!-- RWA 1990 Jan 24180.77 14969.988 -->
<!-- RWA 1990 Feb 23650.53 11791.464 -->
<!-- RWA 1990 Mar 21860.14 30047.979 -->
<!-- RWA 1990 Apr 20801.06 19853.556 -->
<!-- RWA 1990 May 18702.84 5148.118 -->
<!-- RWA 1990 Jun 30272.37 48625.140 -->
<!-- ``` -->
There are 264 observations for 5 countries (Angola, Benin, France, Rwanda, and UK) stored in the ```ccode``` variable, over a time period between 1990 to 1999 (```year```) with additional information for the month (```month```). Additionally, two artificially generated fake variables for GDP (```gdp```) and population size (```population```) are included to illustrate of conditions.
The following functions work best on data sets that have an id-time-structure, in the case of `toydata` this corresponds to country-year with `ccode` and `year`.
If the data set does not have this format yet, consider using [```pivot_wider()``` or ```pivot_longer()```](https://tidyr.tidyverse.org/reference/pivot_longer.html) to get to the format.
### ```overview_tab```
Generate some general overview of the data set using the time and scope conditions with ```overview_tab```.
```{r, message=FALSE, warning=FALSE, eval=FALSE}
output_table <- overview_tab(dat = toydata, id = ccode, time = year)
```
The resulting data frame collapses the time condition for each id by taking into account potential gaps in the time frame. Note that the column name for the time frame is set by default to `time_frame` and internally generated when using `overview_tab`.
```{r, message=FALSE, eval=FALSE}
output_table
```
```
# ccode time_frame
# RWA 1990 - 1995
# AGO 1990 - 1992
# BEN 1995 - 1999
# GBR 1991, 1993, 1995, 1997, 1999
# FRA 1993, 1996, 1999
```
### Multiple time arguments
As of overviewR version 0.0.7 you can also use multiple time objects in `overview_tab`. You can now pass a list containing multiple time variables with the following format: `time = list(year = NULL, month = NULL, day = NULL)`.
```{r, message=FALSE, eval=FALSE}
output_table_complex <- overview_tab(dat = toydata, id = ccode, time = list(year = toydata$year,
month = toydata$month, day = toydata$day), complex_date = TRUE)
```
The resulting data frame collapses again the time condition for each id by taking into account potential gaps in the time frame. Note that the column name for the time frame is set by default to `time_frame` and internally generated when using `overview_tab`. The output resembles something like this:
```{r, message=FALSE, eval=FALSE}
output_table_complex
```
```
ccode time_frame # AGO 1990-01-01, 1990-02-02, 1990-03-03, 1990-04-04, 1990-05-05, 1990-06-06, ...
# BEN 1995-01-01, 1995-02-02, 1995-03-03, 1995-04-04, 1995-05-05, 1995-06-06, ...
# FRA 1993-01-01, 1993-02-02, 1993-03-03, 1993-04-04, 1993-05-05, 1993-06-06, ...
# GBR 1991-01-01, 1991-02-02, 1991-03-03, 1991-04-04, 1991-05-05, 1991-06-06, ...
# RWA 1990-01-01 - 1990-01-12, 1991-01-01 - 1991-01-12, 1992-01-01 - 1992-01-12, 1993-01-01 - 1993-01-12, 1994-01-01
```
### ```overview_crosstab```
To generate a cross table that divides the data based on two conditions, for instance GDP and population size, ```overview_crosstab``` can be used. `threshold1` and `threshold2` thereby indicate the cut point for the two conditions (`cond1` and `cond2`), respectively.
```{r, message=FALSE, warning=FALSE, eval=FALSE}
output_crosstab <- overview_crosstab(
dat = toydata,
cond1 = gdp,
cond2 = population,
threshold1 = 25000,
threshold2 = 27000,
id = ccode,
time = year
)
```
The data frame output looks as follows:
```{r, message=FALSE, echo=FALSE, eval=FALSE}
output_crosstab
```
```
# part1 part2
# 1 AGO (1990, 1992), FRA (1993), GBR (1997) BEN (1996, 1999), FRA (1999), GBR (1993), RWA (1992, 1994)
# 2 BEN (1997), RWA (1990) AGO (1991), BEN (1995, 1998), FRA (1996), GBR (1991, 1995, 1999), RWA (1991, 1993, 1995)
```
Note, if a data set is used that has multiple observations on the id-time unit, the function automatically aggregates the data set using the mean of condition 1 (`cond1`) and condition 2 (`cond2`).
### ```overview_latex```
> With overviewR v 0.0.11.999 we introduced `overview_latex` instead of `overview_print`
To generate an easily usable LaTeX output for the generated `overview_tab` and `overview_crosstab` objects, `overviewR` offers the function `overview_latex`.
The following illustrate this using the `output_table` object from `overview_tab`.
```{r, eval=FALSE}
overview_latex(obj = output_table)
```
<details>
<summary>LaTeX output</summary>
```{r, eval=FALSE, include=FALSE}
overview_latex(obj = output_table)
```
```
% Overview table generated in R version 4.0.0 (2020-04-24) using overviewR
% Table created on 2020-06-21
\begin{table}[ht]
\centering
\caption{Time and scope of the sample}
\begin{tabular}{ll}
\hline
Sample & Time frame \\
\hline
RWA & 1990 - 1995 \\
AGO & 1990 - 1992 \\
BEN & 1995 - 1999 \\
GBR & 1991, 1993, 1995, 1997, 1999 \\
FRA & 1993, 1996, 1999 \\
\hline
\end{tabular}
\end{table}
```
</details>
<p align="center">
<img src='man/figures/ex1.png' height="150"/>
</p>
The default already provides a title ("Time and scope of the sample") that can be modified in the argument `title`. The same holds for the column names ("Sample" and "Time frame" are set by default but can be modified as shown below).
```{r, eval = FALSE, eval=FALSE}
overview_latex(
obj = output_table,
id = "Countries",
time = "Years",
title = "Cool new title for our awesome table"
)
```
<details>
<summary>LaTeX output</summary>
```{r, eval=FALSE, include=FALSE}
overview_latex(
obj = output_table,
id = "Countries",
time = "Years",
title = "Cool new title for our awesome table"
)
```
```
% Overview table generated in R version 4.0.0 (2020-04-24) using overviewR
% Table created on 2020-06-21
\begin{table}[ht]
\centering
\caption{Cool new title for our awesome table}
\begin{tabular}{ll}
\hline
Countries & Years \\
\hline
RWA & 1990 - 1995 \\
AGO & 1990 - 1992 \\
BEN & 1995 - 1999 \\
GBR & 1991, 1993, 1995, 1997, 1999 \\
FRA & 1993, 1996, 1999 \\
\hline
\end{tabular}
\end{table}
```
</details>
<p align="center">
<img src='man/figures/ex2.png' height="150"/>
</p>
The same function can also be used for outputs from the `overview_crosstab` function by using the argument `crosstab = TRUE`. There are also options to label the respective conditions (```cond1``` and ```cond2```). Note that this should correspond to the conditions (```cond1``` and ```cond2```) specified in the `overview_crosstab` function.
```{r, eval = FALSE}
overview_latex(
obj = output_crosstab,
title = "Cross table of the sample",
crosstab = TRUE,
cond1 = "GDP",
cond2 = "Population"
)
```
<details>
<summary>LaTeX output</summary>
```{r, eval=FALSE, include=FALSE}
overview_latex(
obj = output_crosstab,
title = "Cross table of the sample",
crosstab = TRUE,
cond1 = "GDP",
cond2 = "Population"
)
```
```
% Overview table generated in R version 4.0.0 (2020-04-24) using overviewR
% Table created on 2020-06-21
% Please add the following packages to your document preamble:
% \usepackage{multirow}
% \usepackage{tabularx}
% \newcolumntype{b}{X}
% \newcolumntype{s}{>{\hsize=.5\hsize}X}
\begin{table}[ht]
\caption{Cross table of the sample}
\begin{tabularx}{\textwidth}{ssbb}
\hline & & \multicolumn{2}{c}{\textbf{GDP}} \\
& & \textbf{Fulfilled} & \textbf{Not fulfilled} \\
\hline \\
\multirow{2}{*}{\textbf{Population}} & \textbf{Fulfilled} &
AGO (1990, 1992), FRA (1993), GBR (1997) & BEN (1996, 1999), FRA (1999), GBR (1993), RWA (1992, 1994)\\
\\ \hline \\
& \textbf{Not fulfilled} & BEN (1997), RWA (1990) & AGO (1991), BEN (1995, 1998), FRA (1996), GBR (1991, 1995, 1999), RWA (1991, 1993, 1995)\\ \hline \\
\end{tabularx}
\end{table}
```
</details>
<p align="center">
<img src='man/figures/ex3.png' height="200"/>
</p>
`overview_latex` further allows more specifications such as the font size or a a label. *These functions are currently supported only in the development version of the package.*
```{r, eval = FALSE}
overview_latex(obj = output_table,
fontsize = "scriptsize",
label = "tab:overview")
```
With ```save_out = TRUE``` the function exports the output as a ```.tex``` file and stores it on the device.
```{r, eval = FALSE}
overview_latex(
obj = output_table,
save_out = TRUE,
file_path = "SET-YOUR-PATH/output.tex"
)
```
### ```overview_plot```
In addition to tables, `overviewR` also provides plots to illustrate the structure of your data.
`overview_plot` illustrates the information that is generated in `overview_table` in a ggplot graphic. All scope objects (e.g., countries) are listed on the y-axis where horizontal lines indicate the coverage across the entire time frame of the data (x-axis). This helps to spot gaps in the data for specific scope objects and outlines at what time point they occur.
```{r, out.width = '50%', fig.align='center'}
data(toydata)
overview_plot(dat = toydata, id = ccode, time = year)
```
The results are sorted alphabetically by default. The order can also be reversed by setting `asc` to `FALSE`.
```{r, out.width = '50%', fig.align='center'}
library(magrittr) # A Forward-Pipe Operator for R
overview_plot(
dat = toydata,
id = ccode,
time = year,
asc = FALSE
)
```
There is also an option to color the time lines conditionally. Here, we introduce a dummy variable that indicates whether the year was before 1995 or not. We use this dummy to color the time lines using the `color` argument.
```{r, out.width = '50%', fig.align='center', include = TRUE, results = TRUE, message = FALSE, warning=FALSE}
# Code whether a year was before 1995
toydata <- toydata %>%
dplyr::mutate(before = ifelse(year < 1995, 1, 0))
# Plot using the `color` argument
overview_plot(
dat = toydata,
id = ccode,
time = year,
color = before
)
```
The development version also allows to change the dot size using the `dot_size` argument. The default is "2".
```{r, eval = FALSE}
# Plot using the `color` argument
overview_plot(
dat = toydata,
id = ccode,
time = year,
dot_size = 5
)
```
<p align="center">
<img src='man/figures/dot.png' height="400"/>
</p>
### ```overview_crossplot```
To visualize also the cross table, `overview_crossplot` does the job.
```{r, out.width = '50%', fig.align='center', include = TRUE, results = TRUE, message = FALSE, warning=FALSE}
overview_crossplot(
toydata,
id = ccode,
time = year,
cond1 = gdp,
cond2 = population,
threshold1 = 25000,
threshold2 = 27000,
color = TRUE,
label = TRUE
)
```
### ```overview_heat```
`overview_heat` takes a closer look at the time and scope conditions by visualizing the data coverage for each time and scope combination in a ggplot heat map. This function is best explained using an example. Suppose you have a dataset with monthly data for different countries and want to know if data is available for each country in every month. `overview_heat` intuitively does this by plotting a heat map where each cell indicates the coverage for that specific combination of time and scope (e,g., country-year). As illustrated below, the darker the cell is, the more coverage it has. The plot also indicates the relative or absolute coverage of each cell. For instance, Angola ("AGO") in 1991 shows the coverage of 75%. This means that of all potential 12 months of coverage (12 months for one year), only 9 are covered.
For this purpose, we first artificially reduced the `toydata`.
```{r, include = TRUE}
toydata_red <- toydata[-sample(seq_len(nrow(toydata)), 64),]
```
```{r, out.width = '50%', fig.align='center'}
overview_heat(toydata_red,
ccode,
year,
perc = TRUE,
exp_total = 12)
```
### ```overview_na```
`overview_na` is a simple function that provides information about the content of all variables in your data, not only the time and scope conditions. It returns a horizontal ggplot bar plot that indicates the amount of missing data (NAs) for each variable (on the y-axis). You can choose whether to display the relative amount of NAs for each variable in percentage (the default) or the total number of NAs.
For this purpose, we first artificially reduced our `toydata`.
```{r, include=TRUE}
toydata_with_na <- toydata %>%
dplyr::mutate(
year = ifelse(year < 1992, NA, year),
month = ifelse(month %in% c("Jan", "Jun", "Aug"), NA, month),
gdp = ifelse(gdp < 20000, NA, gdp)
)
```
```{r, out.width = '50%', fig.align='center'}
overview_na(toydata_with_na)
```
```{r, out.width = '50%', fig.align='center'}
overview_na(toydata_with_na, perc = FALSE)
```
### ```overview_overlap```
This function allows to compare two data sets. We are currently working on an extended version that allows comparing >2 data sets.
At the current development stage, the function works as follows:
```{r, eval=TRUE, out.width = '50%', fig.align='center'}
library(dplyr)
# Subset one data set for comparison
toydata2 <- toydata %>% dplyr::filter(year > 1992)
overview_overlap(
dat1 = toydata,
dat2 = toydata2,
dat1_id = ccode,
dat2_id = ccode,
plot_type = "bar" # This is the default
)
```
<!--<p align="center">
<img src='man/figures/bar.png' height="400"/>
</p>-->
Or a Venn diagram
```{r, eval = TRUE,out.width = '50%', fig.align='center'}
overview_overlap(
dat1 = toydata,
dat2 = toydata2,
dat1_id = ccode,
dat2_id = ccode,
plot_type = "venn"
)
```
<!--<p align="center">
<img src='man/figures/venn.png' height="400"/>
</p>
-->
## Compatibilities with other packages
### Presenting tables: `flextable`, `xtable`, and `kable`
The outputs of `overview_tab` and `overview_crosstab` are also compatible with other functions such as [`xtable`](https://CRAN.R-project.org/package=xtable), [`flextable`](https://CRAN.R-project.org/package=flextable), or [`kable`](https://bookdown.org/yihui/rmarkdown-cookbook/kable.html) from [`knitr`](https://yihui.org/knitr/).
Two examples are shown below:
```{r, eval=FALSE}
library(flextable) # not installed on this machine
table_output <- qflextable(output_table)
table_output <-
set_header_labels(table_output,
ccode = "Countries",
time_frame = "Time frame")
set_table_properties(table_output,
width = .4,
layout = "autofit")
```
```{r, echo=FALSE, include=FALSE}
output_table <-
data.frame(
ccode = c("RWA", "AGO", "BEN", "GBR", "FRA"),
time_frame = c(
"1990-1995",
"1990-1992",
"1995-1999",
"1991, 1993, 1995, 1997, 1999",
"1993, 1996, 1999"
)
)
```
```{r}
library(knitr) # A General-Purpose Package for Dynamic Report Generation in R
knitr::kable(output_table)
```
### Customizing plots: `ggplot2` and other packages
The plot functions are fully `ggplot2` based. While a theme is pre-defined, this can easily be overwritten.
A classical `ggplot2` theme alternative
```{r, out.width = '50%', fig.align='center'}
library(ggplot2) # Create Elegant Data Visualisations Using the Grammar of Graphics
overview_na(toydata_with_na) +
ggplot2::theme_minimal()
```
### Workflow: `tidyverse`
All functions are further easily accessible using a common `tidyverse` workflow. Here are just three examples -- the possibilities are endless.
Using a filter function
```{r, out.width = '50%', fig.align='center'}
library(dplyr) # A Grammar of Data Manipulation # A Grammar of Data Manipulation
toydata_with_na %>%
dplyr::filter(year > 1993) %>%
overview_na()
```
Using mutate to generate meaningful country names
```{r, out.width = '50%', fig.align='center'}
library(countrycode) # Convert Country Names and Country Codes
library(dplyr) # A Grammar of Data Manipulation # A Grammar of Data Manipulation
toydata %>%
# Transform the country code (ISO3 character code) into a country name using the `countrycode` package
dplyr::mutate(country = countrycode::countrycode(ccode, "iso3c", "country.name")) %>%
overview_plot(id = country, time = year)
```
Using different `overviewR` functions after each other to generate a workflow
```{r, eval = FALSE}
# Produces a printable LaTeX output
toydata %>%
overview_tab(id = ccode, time = year) %>%
overview_latex()
```
```
% Overview table generated in R version 4.0.2 (2020-06-22) using overviewR
% Table created on 2020-12-30
\begin{table}[ht]
\centering
\caption{Time and scope of the sample}
\label{tab:tab1}
\begin{tabular}{ll}
\hline
Sample & Time frame \\
\hline
AGO & 1990 - 1992 \\
BEN & 1995 - 1999 \\
FRA & 1993, 1996, 1999 \\
GBR & 1991, 1993, 1995, 1997, 1999 \\
RWA & 1990 - 1995 \\
\hline
\end{tabular}
\end{table}
```
## Overview of functional add-ons
| | Works with `data.frame` objects | Works with `data.table` | Can take multiple time arguments (year, month, day) |
|-----------------------|---------------------------------|-------------------------|-----------------------------------------------------|
| `overview_tab` | ✓ | ✓ | ✓ |
| `overview_na` | ✓ | ✓ | |
| `overview_plot` | ✓ | | |
| `overview_crossplot` | ✓ | | |
| `overview_crosstab` | ✓ | | |
| `overview_heat` | ✓ | | |
| `overview_overlap` | ✓ | | |
## Extensions
If you wish to compare two data sets using `overview_tab`, this is not (yet) implemented in `overviewR` but there is currently a workaround.
```{r, eval=TRUE}
library(overviewR)
library(dplyr)
library(xtable)
# Load data
data(toydata)
# Restrict the data so that we have something to compare :-)
toydata_res <- toydata %>%
dplyr::filter(year > 1992)
# Generate two overview_tab objects
dat1 <- overview_tab(toydata, id = ccode, time = year)
dat2 <- overview_tab(toydata_res, id = ccode, time = year)
# And now we use full_join to combine both
dat_full <- dat1 %>%
dplyr::full_join(dat2, by = "ccode") %>%
dplyr::rename(time_dat1 = time_frame.x,
time_dat2 = time_frame.y)
```
Having a look at the output, we see that this is exactly what we wanted to have:
```{r, eval=FALSE}
head(dat_full)
```
```
#> # A tibble: 5 x 3
#> # Groups: ccode [5]
#> ccode time_dat1 time_dat2
#> <chr> <chr> <chr>
#> 1 AGO 1990 - 1992 <NA>
#> 2 BEN 1995 - 1999 1995 - 1999
#> 3 FRA 1993, 1996, 1999 1993, 1996, 1999
#> 4 GBR 1991, 1993, 1995, 1997, 1999 1993, 1995, 1997, 1999
#> 5 RWA 1990 - 1995 1993 - 1995
```
`overview_latex` cannot handle this object (yet), so we use `xtable` instead which gives us the LaTeX output.
```{r, eval=FALSE}
print(xtable(dat_full), include.rownames = FALSE)
```
```
% latex table generated in R 4.0.2 by xtable 1.8-4 package
% Tue Feb 16 18:20:51 2021
\begin{table}[ht]
\centering
\begin{tabular}{lll}
\hline
ccode & time\_dat1 & time\_dat2 \\
\hline
AGO & 1990 - 1992 & \\
BEN & 1995 - 1999 & 1995 - 1999 \\
FRA & 1993, 1996, 1999 & 1993, 1996, 1999 \\
GBR & 1991, 1993, 1995, 1997, 1999 & 1993, 1995, 1997, 1999 \\
RWA & 1990 - 1995 & 1993 - 1995 \\
\hline
\end{tabular}
\end{table}
```
</details>
<p align="center">
<img src='man/figures/extension1.png' height="150"/>
</p>
# What's unique about overviewR?
With a specific focus on time-series cross-sectional data, it is unique in its coverage. The details are outlined in the table below:
| Key functionalities | overviewR (0.0.11) | DataExplorer (0.8.2) | dlookR (0.6.0) | gtsummary (1.6.1) | Hmisc (4.7-1) | naniar (0.6.1) | skimr (2.1.4) | smartEDA (0.3.8) | summarytools (1.0.1) |
|-------------------------------------------------------------------------------------|--------------------|----------------------|----------------|-------------------|---------------|----------------|---------------|------------------|----------------------|
| Shows time-series cross-sectional data coverage | ✓ | | | | | | | | |
| Allows to quickly report time-series cross-sectional data coverage (figure/table) | ✓ | | | | | | | | |
| Shows NAs | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Shows NAs (in a figure) | ✓ | ✓ | ✓ | | | ✓ | | | |
| Shows overlap between two data frames (based on time and id) | ✓ | | | | | | | | |
| Shows cross-table | ✓ | | | ✓ | | | | ✓ | ✓ |
| Shows cross-table based on country-year units | ✓ | | | | | | | | |
| Shows cross-tables (in a figure) | ✓ | | | | | | | | |
| Reports descriptive statistics | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Shows value type | | ✓ | ✓ | ✓ | | ✓ | ✓ | ✓ | ✓ |
# How to reach out?
### Where do I report bugs?
Simply [open an issue](https://github.com/cosimameyer/overviewR/issues/new) on GitHub.
### How do I contribute to the package?
If you have an idea (but no code yet), [open an issue](https://github.com/cosimameyer/overviewR/issues/new) on GitHub. If you want to contribute with a specific feature and have the code ready, fork the repository, add your code, and create a pull request.
### Do you need support?
The easiest way is to [open an issue](https://github.com/cosimameyer/overviewR/issues/new) - this way, your question is also visible to others who may face similar problems.
# Credits
The hex sticker is generated by ourselves using the [```hexSticker```](https://github.com/GuangchuangYu/hexSticker) package.