-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransfer
More file actions
35 lines (28 loc) · 1.2 KB
/
Copy pathtransfer
File metadata and controls
35 lines (28 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#Step 5: (Optional) Merge and visualize
library(ggplot2)
ggplot(icu_spo2_summary, aes(x = n_spo2_measurements_first_hour)) +
geom_histogram(binwidth = 1, fill = "darkgreen", color = "black") +
labs(
title = "SpO₂ Measurements in First ICU Hour (After First Contiguous ≥1h Stay)",
x = "Number of SpO₂ Measurements",
y = "Number of Patients"
) +
theme_minimal()
# Assuming `icu_one_hour_start` (the data frame with person_id and icu_start times)
# and `spo2_counts` (the count of SpO₂ measurements) are already available:
# Merge the results from both data frames
icu_spo2_summary <- icu_one_hour_start %>%
left_join(spo2_counts, by = c("person_id", "icu_start")) %>%
mutate(n_spo2_measurements_first_hour = coalesce(n_spo2_measurements_first_hour, 0))
# Check the first few rows of merged data
head(icu_spo2_summary)
# Now plot the histogram
library(ggplot2)
ggplot(icu_spo2_summary, aes(x = n_spo2_measurements_first_hour)) +
geom_histogram(binwidth = 1, fill = "darkgreen", color = "black") +
labs(
title = "SpO₂ Measurements in First ICU Hour (After First Contiguous ≥1h Stay)",
x = "Number of SpO₂ Measurements",
y = "Number of Patients"
) +
theme_minimal()