library(ggplot2)
library(tidyverse)
load("C:/Users/Javi3/Documents/JAVIER/R/Duke/brfss2013.RData")
data1 <- brfss2013 %>% select(cvdinfr4, cvdcrhd4, asthma3, havarth3, sleptim1)
data1$sleptim1 <- gsub("\\b(1|2|3|4|5|6|7)\\b", "Bad Sleepers", data1$sleptim1) #Bad Sleepers
data1$sleptim1 <- gsub("\\b\\d+\\b", "Good Sleepers", data1$sleptim1) #Good Sleepers
The data come from a phone survey and specificaly some questions about the sleep time and if the person has some illness, i wanna see the proportion of Good Sleepers and Bad Sleepers for each illness, for “Good Sleepers” i mean people who spend 8 or more hours asleep
Research quesion 1: What’s the proportion of good and bad dreamers with/without Coronary Heart Disease
Research quesion 2: What’s the proportion of good and bad dreamers with/without Asthma
Research quesion 3: What’s the proportion of good and bad dreamers with/without Arthritis
Research quesion 1: What’s the proportion of good and bad dreamers with/without Coronary Heart Disease
data2 <- data1[!is.na(data1$cvdcrhd4),]
ggplot(data2) + geom_bar(mapping = aes(x = cvdcrhd4, fill = sleptim1), position = "fill") + theme_classic() + scale_fill_brewer(palette = "Accent") + labs(x = "People Diagnosed With Coronary Heart Disease", fill = "Sleepers", caption = "(based on data from BRFSS 2013)")
Research quesion 2: What’s the proportion of good and bad dreamers with/without Asthma
data3 <- data1[!is.na(data1$asthma3),]
ggplot(data3) + geom_bar(mapping = aes(x = asthma3, fill = sleptim1), position = "fill") + theme_classic() + scale_fill_brewer(palette = "Accent") + labs(x = "People Told Have Asthma", fill = "Sleepers", caption = "(based on data from BRFSS 2013)")
Research quesion 3: What’s the proportion of good and bad dreamers with/without Arthritis
data4 <- data1[!is.na(data1$havarth3),]
ggplot(data4) + geom_bar(mapping = aes(x = havarth3, fill = sleptim1), position = "fill") + theme_classic() + scale_fill_brewer(palette = "Accent") + labs(x = "People Told Have Arthritis", fill = "Sleepers", caption = "(based on data from BRFSS 2013)")