Skip to content

Commit

Permalink
Update plotRecordCount
Browse files Browse the repository at this point in the history
  • Loading branch information
martaalcalde committed Jun 21, 2024
1 parent d261a8a commit f110197
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(plotObservationPeriod)
export(plotTableCounts)
export(plotRecordCount)
export(summariseEntryCharacteristics)
export(summariseObservationPeriod)
export(summariseOmopTable)
Expand Down
21 changes: 12 additions & 9 deletions R/plotTableCounts.R
Original file line number Diff line number Diff line change
@@ -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()
}
File renamed without changes.
8 changes: 4 additions & 4 deletions man/plotTableCounts.Rd → man/plotRecordCount.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/summariseRecordCount.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit f110197

Please sign in to comment.