Age vs Hours of Sleep by Gender and Smoking Status(Scatter Plot)


-This dataset provides a well-structured collection of health and lifestyle-related data, covering various aspects such as physical activity, dietary habits, sleep patterns, and medical history and one of them varies by age and gender.

-In this graph, we can explore the relationship between age versus hours of sleep and includes both gender and smoking status. This provides deeper insights into how smoking affects sleep patterns across different genders.

Gender Distribution by Smoker Status(Bar Graph)


This bar plot allows us to see how many smokers and non-smokers there are in each gender group. We can see that there is not a significant different between smokers and nonsmokers by gender.

Hours of Sleep by Heart Disease, Faceted by Gender and Smoking Status(Box Plot)


This box plot helps us visually compare how hours of sleep differ between people with and without heart disease, across different genders and smoking statuses. Essentially exploring, Is there a link between sleep and heart disease? Does that link change based on gender or smoking habits?

Distribution of BMI by Gender(Histogram)


This histogram gives us a clear view of the distribution of BMI across different genders. It helps us understand whether there are gender-based differences in BMI and how BMI values are distributed in the sample.

Density of Calories Intake by Gender (Density Plot)


This graph is a fun way to visualize the distribution of calorie intake, while also highlighting potential differences between genders and how these distributions vary for individuals with different heart disease and Diabetic statuses.

Diabetic Distribution by Gender and Smoker Status(Polar Plot)


This graph compares the distribution of Diabetic status across Gender and Smoker groups. It allows us to see how these factors might influence the prevalence of diabetes. For each gender, the size of each colored wedge shows how common diabetes is. Here we’re trying to answer, Are smokers more likely to be diabetic than non-smokers?Does gender + smoking combine into higher risk?

---
title: "Relation Between Health and Lifestyle"
output: 
  flexdashboard::flex_dashboard:
    storyboard: true
    social: menu
    source: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(ggplot2)
library(ggthemes)
library(plotly)
knitr::opts_chunk$set(echo = TRUE)
setwd("/Users/irania/Downloads")
health_data <- read.csv("health_data.csv")
```

### Age vs Hours of Sleep by Gender and Smoking Status(Scatter Plot)


```{r echo=FALSE}
  ggplotly(
  ggplot(data = health_data, mapping = aes(x = Age, y = Hours_of_Sleep)) +
    geom_point(aes(color = Gender, shape = Gender), size = 3, alpha = 0.7) +  
    geom_smooth(method = 'lm', se = TRUE, color = 'darkblue', size = 1) +   
    facet_grid(Gender ~ Smoker) +  
    labs(
      title = 'Age vs Hours of Sleep by Gender and Smoking Status',
      subtitle = 'Analyzing Sleep Hours with Gender and Smoking Status',
      x = 'Age (years)',
      y = 'Hours of Sleep (per night)',
      color = 'Gender',
      shape = 'Gender'
    ) +
    scale_color_manual(values = c('Male' = '#1f77b4', 'Female' = '#ff7f0e')) +  # More distinct colors
    theme_minimal() + 
    theme(
      plot.title = element_text(hjust = 0.5, size = 14, face = "bold"), 
      plot.subtitle = element_text(hjust = 0.5, size = 6),  
      axis.title = element_text(size = 12, face = "bold"),  
      axis.text = element_text(size = 10),  
      strip.text = element_text(size = 12, face = "bold"),  
      legend.position = "top"  
    ))
```

***
-This dataset provides a well-structured collection of health and lifestyle-related data, covering various aspects such as physical activity, dietary habits, sleep patterns, and medical history and one of them varies by age and gender. 

-In this graph, we can explore the relationship between age versus hours of sleep and includes both gender and smoking status. This provides deeper insights into how smoking affects sleep patterns across different genders.



### Gender Distribution by Smoker Status(Bar Graph)

```{r echo=FALSE}
  ggplot(health_data, aes(x = Gender, fill = Smoker)) +
    geom_bar(width = 0.7) +  
    theme_minimal() +  
    labs(
      title = "Gender Distribution by Smoker Status",
      subtitle = "Shows the Count of Smokers and Non-Smokers by Gender",
      x = "Gender",
      y = "Count",
      fill = "Smoker Status"
    ) +
    scale_fill_manual(values = c("Yes" = "#FF6347", "No" = "#BCEE68")) + 
    coord_flip() +  
    theme(
      plot.title = element_text(hjust = 0.5, size = 11, face = "bold"), 
      plot.subtitle = element_text(hjust = 0.5, size = 10),  
      axis.title = element_text(size = 12, face = "bold"),  
      axis.text = element_text(size = 10),  
      legend.position = "top",  
      strip.text = element_text(size = 12, face = "bold")  
    )
```

***
This bar plot allows us to see how many smokers and non-smokers there are in each gender group. We can see that there is not a significant different between smokers and nonsmokers by gender.


### Hours of Sleep by Heart Disease, Faceted by Gender and Smoking Status(Box Plot)

```{r echo=FALSE}
  ggplot(health_data, aes(x = Heart_Disease, y = Hours_of_Sleep, fill = Heart_Disease)) +
    geom_boxplot(outlier.colour = "red", outlier.size = 2, alpha = 0.5, color = "blue") + 
    facet_wrap(Gender ~ Smoker) + 
    theme_minimal() +
    labs(
      title = "Hours of Sleep by Heart Disease, Faceted by Gender and Smoking Status",
      subtitle = "Boxplots show distribution of hours of sleep based on heart disease status",
      x = "Heart Disease Status",
      y = "Hours of Sleep",
      fill = "Heart Disease",
      color = "Heart Disease"
    ) +
    scale_fill_manual(values = c("Yes" = "#FF6347", "No" = "#4682B4")) + 
    theme(
      plot.title = element_text(hjust = 0.5, size = 11, face = "bold"),
      plot.subtitle = element_text(hjust = 0.5, size = 10),
      axis.title = element_text(size = 10, face = "bold"),
      axis.text = element_text(size = 10),
      strip.text = element_text(size = 10, face = "bold"),
      legend.position = "top"  
    )
```


***
This box plot helps us visually compare how hours of sleep differ between people with and without heart disease, across different genders and smoking statuses. Essentially exploring, Is there a link between sleep and heart disease? Does that link change based on gender or smoking habits?



### Distribution of BMI by Gender(Histogram)

```{r echo=FALSE}
ggplot(health_data, aes(x = BMI, fill = Gender)) +
      geom_histogram(binwidth = 1, color = "black", alpha = 0.6, position = "dodge") + 
      facet_wrap(~Gender) +
      theme_minimal() +
      labs(
        title = "Distribution of BMI by Gender",
        subtitle = "BMI distribution for males and females",
        x = "Body Mass Index (BMI)",
        y = "Frequency"
      ) +
      scale_fill_manual(values = c("Male" = "#1F77B4", "Female" = "#FFBBFF")) +  # Custom colors for Gender
      theme(
        plot.title = element_text(hjust = 0.5, size = 11, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5, size = 10),
        axis.title = element_text(size = 12, face = "bold"),
        axis.text = element_text(size = 10),
        strip.text = element_text(size = 12, face = "bold"),
        legend.position = "top",  
        panel.grid.major = element_line(color = "gray90"),  
        panel.grid.minor = element_blank()  
      )
```


***
This histogram gives us  a clear view of the distribution of BMI across different genders. It helps us understand whether there are gender-based differences in BMI and how BMI values are distributed in the sample. 


### Density of Calories Intake by Gender (Density Plot)

```{r echo=FALSE}

facet_labels <- c("Yes" = "Heart Disease: Yes", "No" = "Heart Disease: No")
    ggplotly(
    ggplot(health_data, aes(x = Calories_Intake, color = Gender, fill = Gender)) +
      geom_density(alpha = 0.3, size = 1.2) +  
      facet_wrap(Heart_Disease ~ Diabetic, scales = "free_y", labeller = labeller(Heart_Disease = facet_labels)) +  
      theme_minimal() +
      labs(
        title = "Density of Calories Intake by Gender",
        subtitle = "Faceted by Heart Disease and Diabetes Status",
        x = "Calories Intake (kcal)",
        y = "Density"
      ) +
      scale_color_manual(values = c("Male" = "#1F77B4", "Female" = "#FF7F0E")) + 
      scale_fill_manual(values = c("Male" = "#1F77B4", "Female" = "#FF7F0E")) +
      theme(
        plot.title = element_text(hjust = 0.5, size = 11, face = "bold"),  
        plot.subtitle = element_text(hjust = 0.5, size = 6),  
        axis.title = element_text(size = 12, face = "bold"),
        axis.text = element_text(size = 10),
        strip.text = element_text(size = 12, face = "bold"),  
        legend.position = "top",  
        panel.grid.major = element_line(color = "gray90"),  
        panel.grid.minor = element_blank()  
      ))
```

***

This graph is a fun  way to visualize the distribution of calorie intake, while also highlighting potential differences between genders and how these distributions vary for individuals with different heart disease and Diabetic statuses.

### Diabetic Distribution by Gender and Smoker Status(Polar Plot)

```{r echo=FALSE}
 ggplot(health_data, aes(x = Gender, fill = Diabetic)) +
    geom_bar() +
    coord_polar() + 
    facet_wrap(~Smoker) + # Add facets for comparison by Smoker
    labs(title = "Diabetic Distribution by Gender and Smoker Status") +
    theme_minimal()
```

***

This graph compares the distribution of Diabetic status across Gender and Smoker groups. It allows us to see how these factors  might influence the prevalence of diabetes. For each gender, the size of each colored wedge shows how common diabetes is. Here we're trying to answer,  Are smokers more likely to be diabetic than non-smokers?Does gender + smoking combine into higher risk?