# A tibble: 7 × 9
id region school_code gender age place_of_living visible…¹ bpe bpe_v…²
<int> <chr> <fct> <chr> <dbl> <chr> <chr> <chr> <dbl>
1 9 Rīga 60 Meitene 15 Rīga No 16_17 0
2 9 Rīga 60 Meitene 15 Rīga No 11 0
3 9 Rīga 60 Meitene 15 Rīga No 26_27 1
4 9 Rīga 60 Meitene 15 Rīga No 36_37 0
5 9 Rīga 60 Meitene 15 Rīga No 31 0
6 9 Rīga 60 Meitene 15 Rīga No 46_47 0
7 11 Rīga 60 Zēns 15 Pierīga No 16_17 0
# … with abbreviated variable names ¹visible_plaque, ²bpe_value
perio |>group_by(id, age ) %>%summarise(across(starts_with("max"), max)) |>ggplot(aes(x =as.factor(max_bpe))) +geom_bar() +# scale_y_log10() + facet_grid(age ~ . ) +labs(title ="BPE by Age", x ="BPE", y ="n")
`summarise()` has grouped output by 'id'. You can override using the `.groups`
argument.
BPE by gender figure
Show the code
perio |>group_by(id, gender) %>%summarise(across(starts_with("max"), max)) |>ggplot(aes(x =as.factor(max_bpe))) +geom_bar() +# scale_y_log10() + facet_grid(gender ~. ) +labs(title ="BPE by gender", x ="BPE", y ="n")
`summarise()` has grouped output by 'id'. You can override using the `.groups`
argument.
BPE by Quadrant figure
Show the code
perio |>pivot_longer("11":"46_47", names_to ="bpe", values_to ="value") |>ggplot(aes(x = bpe, y = value, fill =as.factor(value))) +scale_fill_viridis_d() +geom_col() +labs(title ="BPE per quadrant", fill ="BPE", x ="Quadrant", y ="n")
Source Code
---title: "02_perio_eadph"format: html: code-fold: true code-tools: true code-summary: "Show the code"editor: visual---# Packages```{r}pacman::p_load(tidyverse, here, janitor, kableExtra, viridis, DescTools, gtsummary)``````{r}theme_set(theme_minimal())```# Dataset```{r}#| echo: false#| warning: false# This is the filtered data, examination == 1perio <-read_csv(here("data", "df.csv")) |>select(Region, `School code`, Gender, Age, `Place of living`, `Visible plaque`, "20. BPE [16/17]":"20. BPE [46/47]") |>clean_names() |>rowid_to_column("id") |>filter(age %in%c(12, 15)) |>mutate(school_code =as.factor(school_code))``````{r}# to later match with the bpe datasetid <- perio |>select(id:place_of_living)``````{r}head(perio)```# Descriptive```{r}perio |>select(region:place_of_living) |>select(-school_code) |> gtsummary::tbl_summary(by = age)```# BPE| Scoring Codes | Clinical | Criteria ||------------------|------------------|-------------------------------------|| 0 | Pockets \<3.5mm | No calculus/overhangs, no bleeding on probing || | | (black band entirely visible) || 1 | Pockets \<3.5mm | No calculus/overhangs, bleeding on probing || | | (black band entirely visible) || 2 | Pockets \<3.5mm | Supra or subgingival calculus/overhangs || | | (black band entirely visible) || 3 | Probing depth | 3.5-5.5mm || | | (Black band partially visible, indicating pocket || | | of 4-5mm) || 4 | Probing depth | \>5.5mm || | | (Black band disappears, indicating a pocket of || | | 6mm or more) || 5 | Furcation involvement | |```{r}perio <- perio |>pivot_longer(cols =starts_with("x"),names_to ="bpe",values_to ="bpe_value") |>mutate(bpe =str_remove(bpe, "x20_")) |>extract(bpe, into =c("delete", "bpe"), regex ="^(.*?)_(.*)$", remove =FALSE) |>relocate(bpe_value, .after ="bpe") |>select(-delete)``````{r}perio |>head(7)``````{r}bpe_per_id <- perio |>group_by(id, bpe) |>summarise(max_bpe =max(bpe_value)) |>pivot_wider(names_from = bpe, values_from = max_bpe)``````{r}bpe_per_id <- bpe_per_id |>mutate(max_bpe =max(across("11":"46_47")))```add the demographic information```{r}perio <- id |># select(id:place_of_living ) |> left_join(bpe_per_id, by ="id") |># select(-(ends_with(".y"))) |> rename_at(vars(ends_with(".x")), ~gsub("\\.x", "", .))``````{r}rm(id, bpe_per_id)```## Max BPE per id```{r}perio |>group_by(id) %>%summarise(across(starts_with("max"), max))```How many per age?```{r}perio |>count(age)``````{r}perio |>select(age, max_bpe) |> gtsummary::tbl_summary(by = age)```### BPE per quadrant```{r}perio |>pivot_longer("11":"46_47", names_to ="quadrant", values_to ="bpe_value") |>select(quadrant, bpe_value) |> gtsummary::tbl_summary(by = quadrant)```### BPE by age table```{r}perio |>group_by(id, age) |>summarise(across(starts_with("max"), max)) |>group_by(max_bpe, age) |>count() |>pivot_wider(names_from = age, values_from = n)```### BPE by age figure```{r}perio |>group_by(id, age ) %>%summarise(across(starts_with("max"), max)) |>ggplot(aes(x =as.factor(max_bpe))) +geom_bar() +# scale_y_log10() + facet_grid(age ~ . ) +labs(title ="BPE by Age", x ="BPE", y ="n")```### BPE by gender figure```{r}perio |>group_by(id, gender) %>%summarise(across(starts_with("max"), max)) |>ggplot(aes(x =as.factor(max_bpe))) +geom_bar() +# scale_y_log10() + facet_grid(gender ~. ) +labs(title ="BPE by gender", x ="BPE", y ="n")```### BPE by Quadrant figure```{r}perio |>pivot_longer("11":"46_47", names_to ="bpe", values_to ="value") |>ggplot(aes(x = bpe, y = value, fill =as.factor(value))) +scale_fill_viridis_d() +geom_col() +labs(title ="BPE per quadrant", fill ="BPE", x ="Quadrant", y ="n")```###