Show the code
df <- summary_primary_diag
df <- df %>% mutate(
label = c(paste(round(df$percent[1:5]), "%", sep = ""), rep(NA, nrow(df) - 5))
)
p0 <- ggplot(data = df, aes(x = reorder(primary_diag, count), y = count, fill = percent)) +
geom_bar(stat = "identity", color = "black") +
coord_polar() +
scale_fill_gradientn(
"Percent",
colours = c("#6C5B7B", "#C06C84", "#F67280", "#F8B195")
) +
geom_text(aes(x = primary_diag, y = count / 2, label = label),
size = 3.5,
color = "black",
fontface = "bold"
) +
scale_y_continuous(
breaks = seq(0, 40000, by = 10000),
limits = c(-10000, 40000),
expand = c(0, 0)
) +
annotate("text", x = 11.95, y = 12000, label = "10,000", size = 2.5, color = "black") +
annotate("text", x = 11.95, y = 22000, label = "20,000", size = 2.5, color = "black") +
annotate("text", x = 11.95, y = 32000, label = "30,000", size = 2.5, color = "black") +
theme(
# Remove axis ticks and text
axis.title = element_blank(),
axis.ticks = element_blank(),
axis.text.y = element_blank(),
# Use gray text for the region names
axis.text.x = element_text(color = "gray12", size = 10),
legend.position = "none",
plot.title = element_text(face = "bold", size = 15),
plot.subtitle = element_text(size = 9)
) +
# Add labels
labs(
title = "\nPatient primary diagnoses",
subtitle = paste(
"\nPrimary diagnoses of admitted patients vary considerably.",
"Even for diabetic encounters, the most common admitting diagnosis is",
"circulatory or heart disease. We will call this out in our analysis,",
"comparing patient outcomes for these high-risk but non-diabetic",
"admissions with diabetic admissions (which are only 9% of the",
"admitting or primary diagnoses).",
sep = "\n"
)
)
# Modifying those with fewer categories
df <- summary_a1c
df <- df %>% mutate(
label = c(paste(round(df$percent), "%", sep = ""))
)
p1 <- ggplot(data = df, aes(x = reorder(a1c, count), y = count, fill = percent)) +
geom_bar(stat = "identity", color = "black", width = 1) +
coord_polar(theta = "x", start = pi / 4) +
scale_fill_gradientn(
"Percent",
colours = c("#F67280", "#F8B195")
) +
# scale_y_continuous(breaks = seq(0, 90000, by = 30000)) +
annotate("text", x = 1.25, y = 22000, label = "20,000", size = 3.5, color = "black") +
annotate("text", x = 1.25, y = 42000, label = "40,000", size = 3.5, color = "black") +
annotate("text", x = 1.25, y = 62000, label = "60,000", size = 3.5, color = "black") +
annotate("text", x = 1.25, y = 82000, label = "80,000", size = 3.5, color = "black") +
geom_text(aes(x = a1c, y = count / 2, label = label),
size = 3.5,
color = "black",
fontface = "bold"
) +
theme(
# Remove axis ticks and text
axis.title = element_blank(),
axis.ticks = element_blank(),
axis.text.y = element_blank(),
# Use gray text for the region names
axis.text.x = element_text(color = "gray12", size = 10),
legend.position = "none",
plot.title = element_text(face = "bold", size = 15),
plot.subtitle = element_text(size = 9)
) +
# Add labels
labs(
title = "\nHbA1c test measurement",
subtitle = paste(
"\nEven though these are all diabetic encounters, for 83% of patients",
"an HbA1c value is not measured. This is a vital insight, since HbA1c",
"is a critical tool to assess patient outcomes and to calculate insulin",
"dosage (see text for source**).",
sep = "\n"
)
)
df <- summary_readmitted
df <- df %>% mutate(
label = c(paste(round(df$percent), "%", sep = ""))
)
p2 <- ggplot(data = df, aes(x = reorder(readmitted, count), y = count, fill = percent)) +
geom_bar(stat = "identity", color = "black", width = 1) +
coord_polar(theta = "x") +
scale_fill_gradientn(
"Percent",
colours = c("#F67280", "#F8B195")
) +
geom_text(aes(x = readmitted, y = count / 2, label = label),
size = 3.5,
color = "black",
fontface = "bold"
) +
scale_y_continuous(breaks = seq(0, 50000, by = 10000)) +
annotate("text",
x = 1, y = 18000, label = "20,000", size = 3.5, color = "black",
angle = -60
) +
annotate("text",
x = 1, y = 28000, label = "30,000", size = 3.5, color = "black",
angle = -60
) +
annotate("text",
x = 1, y = 38000, label = "40,000", size = 3.5, color = "black",
angle = -60
) +
annotate("text",
x = 1, y = 48000, label = "50,000", size = 3.5, color = "black",
angle = -60
) +
theme(
# Remove axis ticks and text
axis.title = element_blank(),
axis.ticks = element_blank(),
axis.text.y = element_blank(),
# Use gray text for the region names
axis.text.x = element_text(color = "gray12", size = 13),
legend.position = "none",
plot.title = element_text(face = "bold", size = 15),
plot.subtitle = element_text(size = 9)
) +
# Add labels
labs(
title = "\nReadmissions",
subtitle = paste(
"\nReadmission after discharge is an important downstream patient",
"outcome, due to the cost burden it levies on the healthcare system.",
"Almost 50% of patients are readmitted, and 11% are readmitted early-",
"<30 days after being discharged. We will use this (early readmit)",
"as our primary outcome in the final analysis.",
sep = "\n"
)
)
df <- summary_diabetesMed
df <- df %>% mutate(
label = c(paste(round(df$percent), "%", sep = ""))
)
p3 <- ggplot(data = df, aes(x = reorder(diabetesMed, count), y = count, fill = percent)) +
geom_bar(stat = "identity", color = "black", width = 1) +
coord_polar(theta = "x", start = pi / 4) +
scale_fill_gradientn(
"Percent",
colours = c("#F67280", "#F8B195")
) +
annotate("text", x = 1.25, y = 26000, label = "25,000", size = 3.5, color = "black") +
annotate("text", x = 1.25, y = 41000, label = "40,000", size = 3.5, color = "black") +
annotate("text", x = 1.25, y = 61000, label = "60,000", size = 3.5, color = "black") +
annotate("text", x = 1.25, y = 81000, label = "80,000", size = 3.5, color = "black") +
geom_text(aes(x = diabetesMed, y = count / 2, label = label),
size = 3.5,
color = "black",
fontface = "bold"
) +
theme(
# Remove axis ticks and text
axis.title = element_blank(),
axis.ticks = element_blank(),
axis.text.y = element_blank(),
# Use gray text for the region names
axis.text.x = element_text(color = "gray12", size = 10),
legend.position = "none",
plot.title = element_text(face = "bold", size = 15),
plot.subtitle = element_text(size = 9)
) +
# Add labels
labs(
title = "\nDiabetes medications",
subtitle = paste(
"\nThough these are all diabetic encounters, we see that 23% of patients",
"are never given diabetes medications. In our analysis, we will also",
"dive deeper into what this means, and how downstream outcomes of these",
"patients are impacted by this intermediate care delivery variable.",
sep = "\n"
)
)
grid.arrange(p0, p1, p3, p2, nrow = 2, ncol = 2)