Code
library(tidyverse)library(tidyverse)df_bp <-
readstata13::read.dta13("C:/Dataset/BP.dta") %>%
select(sex, sbp, dbp, saltadd) %>%
pivot_longer(
cols = c(sbp, dbp),
values_to = "pressure",
names_to = "bp_type")
dataF <- readstata13::read.dta13("C:/Dataset/olivia_data_wide.dta")df_bp %>%
filter(bp_type == "sbp") %>%
ggplot(aes(x = pressure)) +
geom_density(
color = "blue",
fill = 'red',
linetype = "dashed",
alpha = 0.2) +
theme_light()
df_bp %>%
filter(bp_type == "sbp") %>%
drop_na(saltadd) %>%
ggplot(aes(x = pressure, color = saltadd, fill = saltadd)) +
geom_density(
linetype = "dashed", alpha = 0.2) +
theme_light()+
scale_color_brewer(palette = "Dark2")
df_bp %>%
drop_na(saltadd) %>%
ggplot(aes(x = pressure, color = saltadd)) +
geom_density(aes(fill = saltadd), linetype = "dashed", alpha = 0.2) +
theme_light()+
scale_color_brewer(palette = "Dark2") +
facet_grid(bp_type ~ sex)
df_bp %>%
drop_na(saltadd) %>%
ggplot(aes(x = pressure, fill = bp_type)) +
ggridges::geom_density_ridges(aes(y = saltadd), alpha = .3) +
labs(x = "Pressure",
y = "Salt added to diet") +
ggridges::theme_ridges(font_size = 12) +
scale_fill_discrete(
name = "Blood Pressure Type",
labels = c("sbp" = "Systolic", "dbp" = "Diastolic")) +
theme(legend.position = "right")Picking joint bandwidth of 11.5
dataF %>%
select(mcv1, mcv2, mcv3, mcv4, mcv5, agecat, id) %>%
pivot_longer(cols = mcv1:mcv5, names_to = "Time", values_to = "MCV") %>%
ggplot(aes(x = MCV, fill = Time)) +
ggridges::geom_density_ridges(aes(y = agecat), alpha = .5) +
labs(x = "MCV",
y = "Age Group Category (years)",
title = "Sequential changes in MCV over the study duration per age category") +
ggridges::theme_ridges() +
scale_fill_discrete(name = "Measure",
labels = c("mcv1" = "First",
"mcv2" = "Second",
"mcv3" = "Third",
"mcv4" = "Fourth",
"mcv5" = "Fifth")) +
theme(legend.position = "right")Picking joint bandwidth of 3.72
