Skip to content

Commit

Permalink
updated some plots functions for the new versions of the functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cecicampanile committed Dec 19, 2024
1 parent 2a15517 commit 0097dd2
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 621 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,4 @@ Depends:
URL: https://OHDSI.github.io/OmopSketch/
BugReports: https://github.com/OHDSI/OmopSketch/issues
VignetteBuilder: knitr
Remotes:

20 changes: 18 additions & 2 deletions R/plotInObservation.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ plotInObservation <- function(result,

# plot
if(length(unique(result$additional_level)) > 1 ){
result |>
dplyr::mutate(additional_level = as.character(gsub("-01$","",as.Date(gsub(" to.*","",.data$additional_level))))) |>
p <- result |>
dplyr::mutate(additional_level = as.character(gsub("-01-01$","",as.Date(gsub(" to.*","",.data$additional_level))))) |>
dplyr::filter(.data$estimate_name == "count") |>
visOmopResults::scatterPlot(
x = "time_interval",
Expand All @@ -78,6 +78,22 @@ plotInObservation <- function(result,
y = variable,
x = "Date"
)
p$data <- p$data |>
dplyr::arrange(time_interval) |>
dplyr::mutate(
show_label = seq_along(time_interval) %%
(10 * nrow(p$data|>dplyr::distinct(.data$omop_table))) == 0 # Show every 10th label
)

p <- p +
ggplot2::scale_x_discrete(
breaks = p$data$time_interval[p$data$show_label]
) +
ggplot2::theme(
axis.text.x = ggplot2::element_text(angle = 90, hjust = 1, size = 8),
plot.margin = ggplot2::margin(t = 5, r = 5, b = 30, l = 5)
)
p
}else{
result |>
dplyr::filter(.data$estimate_name == "count") |>
Expand Down
23 changes: 23 additions & 0 deletions R/plotRecordCount.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ plotRecordCount <- function(result,
y = "Number records",
x = "Date"
)

p$data <- p$data |>
dplyr::mutate(
time_interval = as.character(
gsub("-01-01$", "", as.Date(gsub(" to.*", "", time_interval)))
)
) |>
dplyr::arrange(time_interval) |>
dplyr::mutate(
show_label = seq_along(time_interval) %%
(10 * nrow(p$data|>dplyr::distinct(.data$omop_table))) == 0 # Show every 10th label
)

p <- p +
ggplot2::scale_x_discrete(
breaks = p$data$time_interval[p$data$show_label]
) +
ggplot2::theme(
axis.text.x = ggplot2::element_text(angle = 90, hjust = 1, size = 8),
plot.margin = ggplot2::margin(t = 5, r = 5, b = 30, l = 5)
)
}else{
p <- result |>
visOmopResults::barPlot(x = "variable_name",
Expand All @@ -70,5 +91,7 @@ plotRecordCount <- function(result,
x = ""
)
}

p
}

23 changes: 7 additions & 16 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ summariseClinicalRecords(cdm, c("condition_occurrence", "drug_exposure")) |>
We can also explore trends in the clinical table records over time.

```{r}
summariseRecordCount(cdm, c("condition_occurrence", "drug_exposure")) |>
plotRecordCount(facet = "omop_table")
summariseRecordCount(cdm, c("condition_occurrence", "drug_exposure"), interval = "years") |>
plotRecordCount(facet = "omop_table", colour = "cdm_name")
```

### Characterise the observation period
Expand All @@ -78,8 +78,8 @@ After visualising the main characteristics of our clinical tables, we can explor
Using `summariseInObservation()` and `plotInObservation()`, we can gather information on the number of records per year.

```{r}
summariseInObservation(cdm$observation_period, output = "records") |>
plotInObservation()
summariseInObservation(cdm$observation_period, output = "records", interval = "years") |>
plotInObservation(colour = "cdm_name")
```

You can also visualise and explore the characteristics of the observation period per each individual in the database using `summariseObservationPeriod()`.
Expand All @@ -93,7 +93,7 @@ Or if visualisation is preferred, you can easily build a histogram to explore ho

```{r}
summariseObservationPeriod(cdm$observation_period) |>
plotObservationPeriod()
plotObservationPeriod(colour = "observation_period_ordinal")
```

### Characterise the concepts
Expand All @@ -104,17 +104,8 @@ OmopSketch also provides functions to explore some of (or all) the concepts in t
acetaminophen <- c(1125315, 1127433, 1127078)
summariseConceptSetCounts(cdm, conceptSet = list("acetaminophen" = acetaminophen)) |>
filter(estimate_name == "record_count") |>
plotConceptSetCounts()
```

### Characterise the population

Finally, OmopSketch can also help us to characterise the population at the start and end of the observation period.

```{r}
summarisePopulationCharacteristics(cdm) |>
tablePopulationCharacteristics(type = "flextable")
filter(variable_name == "Number records") |>
plotConceptSetCounts(colour = "codelist_name")
```

As seen, OmopSketch offers multiple functionalities to provide a general overview of a database. Additionally, it includes more tools and arguments that allow for deeper exploration, helping to assess the database's suitability for specific research studies. For further information, please refer to the vignettes.
Loading

0 comments on commit 0097dd2

Please sign in to comment.