library(tidyverse) library(tidybiology) library(viridis) #clear environment #rm(list=ls())
source(here::here("code", "healthcare.R")) #loads dataset-specific variables
##### START HERE ##### #What percent of patients in this dataset are male v. female? heart %>% count(sex, sort = TRUE) freq <- heart %>% group_by(sex) %>% summarize(n = n()) %>% mutate(freq = n/sum(n)) #What is the median age of patients median <- median(heart$age) #What is the average cholesterol level of patients at the median age? avg_chol <- heart %>% filter(age == median(heart$age)) %>% summarize(mean_cholesterol = mean(chol)) #Store a new dataframe object that groups patients by sex and age, and then calculates the average cholesterol levels for patients in this group age_groups <- heart %>% group_by(sex, age) %>% summarize(mean_cholesterol = mean(chol)) #store some of these values, so that you can call them inline below
In the heart study data set, the proportion of females is r freq %>% filter(sex == "female") %>% select(freq) %>% pull()
and males is r freq %>% filter(sex == "male") %>% select(freq) %>% pull()
. The median age of patients in this data set is r median
, which have an average serum cholesterol level of r avg_chol
mg/dl.
heart %>% ggplot(aes(chol, fill = sex)) + geom_density(alpha = 0.5) + theme_bw() + labs( x = "Serum Cholesterol (mg/dl)", y = "Density", fill = "", title = "Distribution of Serum Cholesterol in Men and Women" ) + scale_x_continuous(expand = c(0.005, 0.005)) + scale_y_continuous(expand = c(0, 0)) + geom_vline(data = filter(heart, sex == "male"), aes(xintercept = median(chol)), colour = "yellow", size = 1, linetype = 2) + geom_vline(data = filter(heart, sex == "female"), aes(xintercept = median(chol)), colour = "navy", size = 1, linetype = 2) + scale_fill_viridis(discrete = TRUE, option = "E") #change code chunks so only the report output and plot are shown on the knitted report
#Session information for provenance and reproducibility session_provenance()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.