Code
library(tidyverse)
library(tidyverse)
<-
df_bp ::read.dta13("C:/Dataset/BP.dta") %>%
readstata13select(sex, sbp, dbp, saltadd) %>%
pivot_longer(
cols = c(sbp, dbp),
values_to = "pressure",
names_to = "bp_type")
<- readstata13::read.dta13("C:/Dataset/olivia_data_wide.dta") dataF
%>%
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)) +
::geom_density_ridges(aes(y = saltadd), alpha = .3) +
ggridgeslabs(x = "Pressure",
y = "Salt added to diet") +
::theme_ridges(font_size = 12) +
ggridgesscale_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)) +
::geom_density_ridges(aes(y = agecat), alpha = .5) +
ggridgeslabs(x = "MCV",
y = "Age Group Category (years)",
title = "Sequential changes in MCV over the study duration per age category") +
::theme_ridges() +
ggridgesscale_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