Skip to content

Commit

Permalink
improve heatmap scaling. Close #17
Browse files Browse the repository at this point in the history
  • Loading branch information
phuongquan committed Jun 7, 2024
1 parent 41bdf9d commit 9f3828e
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 8 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

* New `field_types_advanced()` function. Allows just a subset of the columns in the source df to be named explicitly in the specification, with the remaining columns set to the `.default_field_type` parameter. (#16)

## Bug fixes and minor improvements

* Improved scaling of heatmaps when there are lots of fields. (#17)

# daiquiri 1.1.1 (2023-07-18)

Expand Down
2 changes: 1 addition & 1 deletion R/reports.R
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ plot_overview_combo_static <- function(agg_fields,
ncol = 1,
align = "v",
axis = "lr",
rel_heights = c(1, 3)
rel_heights = c(1.4, (length(agg_fields) - ifelse(!is.null(stratum), 1, 0))*0.4)
)
)
}
Expand Down
109 changes: 106 additions & 3 deletions devtesting/changedetectiontesting.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ report_data(testsourcedata, testdata_byday)
# complete test set
testdf <- read_data(test_path("testdata", "completetestset.csv"))
testsourcedata <- prepare_data(testdf,
fieldtypes = fieldtypes( col_timepoint_err = ft_ignore(),
field_types = field_types( col_timepoint_err = ft_ignore(),
col_timepoint = ft_timepoint(),
col_date_time_err = ft_ignore(),
col_date_time = ft_datetime(),
Expand All @@ -64,7 +64,7 @@ testsourcedata <- prepare_data(testdf,
col_simple_err = ft_ignore(),
col_simple = ft_simple()),
dataset_description = "completetestset",
showprogress = FALSE
show_progress = FALSE
)


Expand Down Expand Up @@ -93,7 +93,7 @@ tracemem(df)
class(res)
tracemem(res)

# test default fieldtypes specification
# test default field_types specification
df <- data.frame(
AdmissionDate = rep("2022-01-01", 5),
col2 = rep(1, 5),
Expand Down Expand Up @@ -129,3 +129,106 @@ daiqobj <- daiquiri_report(testdf,

testsourcedata <- prepare_data(df = testdf, field_types = field_types, na=c("","NULL"), show_progress=TRUE)


# many fields
# complete test set
testdf <- read_data(test_path("testdata", "completetestset.csv"))

source_data <- daiquiri::prepare_data(testdf,
field_types = field_types( col_timepoint_err = ft_simple(),
col_timepoint = ft_timepoint(),
col_date_time_err = ft_simple(),
col_date_time = ft_datetime(),
col_date_only_err = ft_simple(),
col_date_only = ft_datetime(includes_time = FALSE),
col_date_uk_err = ft_simple(),
col_date_uk = ft_datetime(includes_time = FALSE, format = "%d/%m/%Y"),
col_id_num_err = ft_simple(),
col_id_num = ft_uniqueidentifier(),
col_id_string_err = ft_simple(),
col_id_string = ft_uniqueidentifier(),
col_numeric_clean_err = ft_simple(),
col_numeric_clean = ft_numeric(),
col_numeric_dirty_err = ft_simple(),
col_numeric_dirty = ft_numeric(),
col_numeric_missing_err = ft_simple(),
col_numeric_missing = ft_numeric(),
col_categorical_small_err = ft_simple(),
col_categorical_small = ft_categorical(),
col_categorical_large_err = ft_simple(),
col_categorical_large = ft_categorical(),
col_freetext_err = ft_simple(),
col_freetext = ft_freetext(),
col_simple_err = ft_simple(),
col_simple = ft_ignore()),
override_column_names = FALSE,
na = c("","NULL","NA"))

aggregated_data <- daiquiri::aggregate_data(source_data,
aggregation_timeunit = "day")

source_data2 <- daiquiri::prepare_data(testdf,
field_types = field_types( col_timepoint_err = ft_simple(),
col_timepoint = ft_timepoint(),
col_date_time_err = ft_simple(),
col_date_time = ft_datetime(),
col_date_only_err = ft_simple(),
col_date_only = ft_datetime(includes_time = FALSE),
col_date_uk_err = ft_simple(),
col_date_uk = ft_datetime(includes_time = FALSE, format = "%d/%m/%Y"),
col_id_num_err = ft_simple(),
col_id_num = ft_uniqueidentifier(),
col_id_string_err = ft_simple(),
col_id_string = ft_uniqueidentifier(),
col_numeric_clean_err = ft_simple(),
col_numeric_clean = ft_numeric(),
col_numeric_dirty_err = ft_simple(),
col_numeric_dirty = ft_numeric(),
col_numeric_missing_err = ft_simple(),
col_numeric_missing = ft_numeric(),
col_categorical_small_err = ft_simple(),
col_categorical_small = ft_strata(),
col_categorical_large_err = ft_simple(),
col_categorical_large = ft_categorical(),
col_freetext_err = ft_simple(),
col_freetext = ft_freetext(),
col_simple_err = ft_simple(),
col_simple = ft_ignore()),
override_column_names = FALSE,
na = c("","NULL","NA"))

aggregated_data2 <- daiquiri::aggregate_data(source_data2,
aggregation_timeunit = "day")

report_data(
source_data,
aggregated_data,
save_directory = "./devtesting/testoutput",
save_filename = NULL,
show_progress = TRUE
)

report_data(
source_data2,
aggregated_data2,
save_directory = "./devtesting/testoutput",
save_filename = NULL,
show_progress = TRUE
)


daiquiri_report(testdf,
field_types = field_types(PrescriptionID = ft_uniqueidentifier()
,PrescriptionDate = ft_timepoint()
,AdmissionDate = ft_datetime(includes_time = FALSE)
,Drug = ft_freetext()
,Dose = ft_numeric()
,DoseUnit = ft_categorical()
,PatientID = ft_ignore()
,Location = ft_strata()),
override_column_names = FALSE,
na = c("","NULL"),
aggregation_timeunit = "day",
save_directory = "./devtesting/testoutput",
save_filename = NULL,
show_progress = TRUE)
22 changes: 18 additions & 4 deletions inst/rmd/report_htmldoc.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,22 @@ agg_fields_strat <- params$aggregated_data$aggregated_fields_stratified
```

```{r daiquiri-aggregated-data-set-fig-height}
# NOTE: can't modify chunk options within a chunk to get different fig heights
# (https://github.com/yihui/knitr/issues/841) so have to make plots consistent for all tabs
overview_values_fig_height <-
1.4 + (length(agg_fields) - ifelse(stratify, 1, 0)) * 0.4
overview_strata_fig_height <-
ifelse(stratify,
(length(strata_labels) + 2) * 0.4,
knitr::opts_chunk$get("fig.height"))
```


```{r daiquiri-overview-strata, results = 'asis'}
```{r daiquiri-overview-strata, results = 'asis', fig.height=overview_strata_fig_height}
if (stratify) {
cat("\n### Strata {.tabset}\n")
Expand Down Expand Up @@ -272,7 +286,7 @@ if (stratify) {

### Values present {.tabset}

```{r daiquiri-overview-presence, results = 'asis'}
```{r daiquiri-overview-presence, results = 'asis', fig.height=overview_values_fig_height}
p_all <-
plot_overview_combo_static(
agg_fields = agg_fields,
Expand Down Expand Up @@ -310,7 +324,7 @@ if (!stratify) {

### Missing values {.tabset}

```{r daiquiri-overview-missing, results = 'asis'}
```{r daiquiri-overview-missing, results = 'asis', fig.height=overview_values_fig_height}
p_all <-
plot_overview_combo_static(
agg_fields = agg_fields,
Expand Down Expand Up @@ -348,7 +362,7 @@ if (!stratify) {

### Non-conformant values {.tabset}

```{r daiquiri-overview-nonconformant, results = 'asis'}
```{r daiquiri-overview-nonconformant, results = 'asis', fig.height=overview_values_fig_height}
p_all <-
plot_overview_combo_static(
agg_fields = agg_fields,
Expand Down

0 comments on commit 9f3828e

Please sign in to comment.