diff --git a/NAMESPACE b/NAMESPACE index cc632fe..893e46b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,7 @@ # Generated by roxygen2: do not edit by hand export(plotObservationPeriod) -export(plotTableCounts) +export(plotRecordCount) export(summariseEntryCharacteristics) export(summariseObservationPeriod) export(summariseOmopTable) diff --git a/R/plotTableCounts.R b/R/plotTableCounts.R index cf02c6e..d3c0bf2 100644 --- a/R/plotTableCounts.R +++ b/R/plotTableCounts.R @@ -1,35 +1,38 @@ #' Create a gt table from a summarised omop_table. #' -#' @param summarisedTableCounts A summarised_result object with the output from summariseTableCounts(). +#' @param summarisedRecordCount A summarised_result object with the output from summariseTableCounts(). #' #' @return A ggplot showing the table counts #' #' @export #' -plotTableCounts <- function(summarisedTableCounts) { +plotRecordCount <- function(summarisedRecordCount){ # Initial checks ---- - assertClass(summarisedTableCounts, "summarised_result") + assertClass(summarisedRecordCount, "summarised_result") - if(summarisedTableCounts |> dplyr::tally() |> dplyr::pull("n") == 0){ + if(summarisedRecordCount |> dplyr::tally() |> dplyr::pull("n") == 0){ cli::cli_warn("summarisedOmopTable is empty.") return( - summarisedTableCounts |> + summarisedRecordCount |> ggplot2::ggplot() ) } # Plot ---- - summarisedTableCounts |> + summarisedRecordCount |> dplyr::mutate(count = as.numeric(.data$estimate_value), time = as.Date(.data$variable_level)) |> - visOmopResults::splitGroup() |> - ggplot2::ggplot(ggplot2::aes(x = .data$time, y = .data$count, group = .data$omop_table, color = .data$omop_table)) + + dplyr::mutate(colour_by = paste0(.data$group_level,"; ",.data$strata_level)) |> + ggplot2::ggplot(ggplot2::aes(x = .data$time, + y = .data$count, + group = .data$colour_by, + color = .data$colour_by)) + ggplot2::geom_point() + ggplot2::geom_line() + ggplot2::facet_wrap(facets = "cdm_name") + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, vjust = 0.5, hjust=1)) + ggplot2::xlab("Time") + ggplot2::ylab("Counts") + - ggplot2::labs(color = "Omop table") + + ggplot2::labs(color = "Stratification") + ggplot2::theme_bw() } diff --git a/R/summariseRecordCounts.R b/R/summariseRecordCount.R similarity index 100% rename from R/summariseRecordCounts.R rename to R/summariseRecordCount.R diff --git a/man/plotTableCounts.Rd b/man/plotRecordCount.Rd similarity index 68% rename from man/plotTableCounts.Rd rename to man/plotRecordCount.Rd index ed00784..893195b 100644 --- a/man/plotTableCounts.Rd +++ b/man/plotRecordCount.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/plotTableCounts.R -\name{plotTableCounts} -\alias{plotTableCounts} +\name{plotRecordCount} +\alias{plotRecordCount} \title{Create a gt table from a summarised omop_table.} \usage{ -plotTableCounts(summarisedTableCounts) +plotRecordCount(summarisedRecordCount) } \arguments{ -\item{summarisedTableCounts}{A summarised_result object with the output from summariseTableCounts().} +\item{summarisedRecordCount}{A summarised_result object with the output from summariseTableCounts().} } \value{ A ggplot showing the table counts diff --git a/man/summariseRecordCount.Rd b/man/summariseRecordCount.Rd index 2fce094..e68d1a4 100644 --- a/man/summariseRecordCount.Rd +++ b/man/summariseRecordCount.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/summariseRecordCounts.R +% Please edit documentation in R/summariseRecordCount.R \name{summariseRecordCount} \alias{summariseRecordCount} \title{Create a gt table from a summarised omop_table.} diff --git a/tests/testthat/test-summariseRecordCounts.R b/tests/testthat/test-summariseRecordCount.R similarity index 96% rename from tests/testthat/test-summariseRecordCounts.R rename to tests/testthat/test-summariseRecordCount.R index 359480c..0e6f161 100644 --- a/tests/testthat/test-summariseRecordCounts.R +++ b/tests/testthat/test-summariseRecordCount.R @@ -76,9 +76,9 @@ test_that("summariseRecordCount() works", { ) # summariseRecordCount plot ---- - expect_true(inherits(plotTableCounts(summariseRecordCount(cdm$drug_exposure, unitInterval = 8)),"ggplot")) - expect_warning(inherits(plotTableCounts(summariseRecordCount(cdm$death, unitInterval = 8)),"ggplot")) - expect_true(inherits(plotTableCounts(summariseRecordCount(cdm$death, unitInterval = 8)),"ggplot")) + expect_true(inherits(plotRecordCount(summariseRecordCount(cdm$drug_exposure, unitInterval = 8)),"ggplot")) + expect_warning(inherits(plotRecordCount(summariseRecordCount(cdm$death, unitInterval = 8)),"ggplot")) + expect_true(inherits(plotRecordCount(summariseRecordCount(cdm$death, unitInterval = 8)),"ggplot")) }) test_that("summariseOmopTable() ageGroup argument works", {