library(tidyverse)
library(patchwork)
bestplot_data <- read.csv("Mental_Health_Lifestyle_Dataset.csv", header=TRUE)

Question 1: Main Message

This plot is meant to demonstrate the breakdown of the presence of mental health conditions by gender. This is important information when looking into the presence of mental health conditions because it gives insight to what groups of people are more likely to have a certain mental health condition.

Visualization 1

count_data <- bestplot_data %>%
  group_by(Gender) %>%
  summarize(count = n())

plot1 <- count_data %>%
  ggplot(aes(x=Gender, y=count)) +
  geom_col()
  
plot1

First, I tried to create a bar graph of mental health condition presence by gender. I initially forgot that I needed to regroup and summarize the data to include counts for different mental health conditions, so this plot is not good at communicating the point that I am trying to make.

Visualization 2

summarized_data <- bestplot_data %>%
  group_by(Gender, Mental.Health.Condition) %>%
  summarize(count = n())

plot2 <- summarized_data %>%
  ggplot(aes(x=Gender, y=count, fill=Mental.Health.Condition)) +
  geom_bar(stat="identity") 

plot2

Second, I created this basic bar graph to see the relationships in the data. The data includes 3 genders (male, female, and other), so those are the three factors that are on the X-axis. I also grouped the data by gender organized into mental health condition counts, so that is the count data that is displayed on the Y-axis.

Visualization 3

plot3 <- summarized_data %>%
  ggplot(aes(x=Gender, y=count, fill=Mental.Health.Condition)) +
  geom_bar(stat="identity", position="dodge") 

plot3

Third, I switched the position of the bars to be side-by-side. This allows the user to more clearly compare the counts of mental health conditions among the different genders in the data.

Visualization 4

plot4 <- summarized_data %>%
  ggplot(aes(x=Gender, y=count, fill=Mental.Health.Condition)) +
  geom_bar(stat="identity", position="dodge") +
  coord_flip() 

plot4

For the fourth iteration of my plot, I flipped the coordinates so that the plot would be easier to read. I believe that flipping the axes allows the reader to read the count bars more clearly.

Visualization 5

p5a <- summarized_data %>% 
  filter(Mental.Health.Condition == "Anxiety") %>%
    ggplot(aes(x = Gender, y = count, fill = Gender)) +
    geom_bar(stat = "identity", position = "dodge") +
    coord_flip() +
    theme_minimal() +
    theme(legend.position="none") +
    labs(title="Anxiety by Gender")

p5b <- summarized_data %>% 
  filter(Mental.Health.Condition == "Bipolar") %>%
    ggplot(aes(x = Gender, y = count, fill = Gender)) +
    geom_bar(stat = "identity", position = "dodge") +
    coord_flip() +
    theme_minimal() +
    theme(legend.position="none") +
    labs(title="Bipolar by Gender")

p5c <- summarized_data %>% 
  filter(Mental.Health.Condition == "Depression") %>%
    ggplot(aes(x = Gender, y = count, fill = Gender)) +
    geom_bar(stat = "identity", position = "dodge") +
    coord_flip() +
    theme_minimal() +
    theme(legend.position="none") +
    labs(title="Depression by Gender")

p5d <- summarized_data %>% 
  filter(Mental.Health.Condition == "PTSD") %>%
    ggplot(aes(x = Gender, y = count, fill = Gender)) +
    geom_bar(stat = "identity", position = "dodge") +
    coord_flip() +
    theme_minimal() +
    theme(legend.position="none") +
    labs(title="PTSD by Gender")

p5e <- summarized_data %>% 
  filter(Mental.Health.Condition == "None") %>%
    ggplot(aes(x = Gender, y = count, fill = Gender)) +
    geom_bar(stat = "identity", position = "dodge") +
    coord_flip() +
    theme_minimal() +
    theme(legend.position="none") +
    labs(title="No Condition by Gender")

plot5 <- p5a + p5b + p5c + p5d + p5e
plot5

For the fifth iteration of my plot, I decided it could be helpful to break up the data into separate plots based on mental health condition. This would allow the user to get a more clear comparison by gender for each individual mental health condition that is in the data.

Visualization 6: Final Best Plot

finalPlot <- summarized_data %>%
  ggplot(aes(x = fct_reorder(Gender, count, .fun = sum, .desc=FALSE), y=count, fill=Mental.Health.Condition)) + 
  geom_bar(stat="identity", position="dodge") + 
  labs(title="Mental Health Conditions by Gender", x="Gender", y="Count", fill="Condition") + 
  coord_flip() + 
  theme_minimal() + 
  scale_fill_manual(values=c("#648FFF", "#785EF0", "#DC267F", "#FE6100", "#FFB000"))

finalPlot

For the final version of my plot, I decided to go back to one single plot because I believe it is easier to read overall. Even though the user doesn’t get the direct gender comparison for each mental health condition, I believe it is significantly easier to read because the viewer is able to see the count data for each condition more clearly. For the final version of the plot, I also changed the color theme to a palette that is colorblind accessible.

Question 2

When creating my Best Plot, I had to make six different iterations in order to achieve a plot that I thought was appropriate. Throughout these six iterations, I made several different aesthetic changes as well. First, I decided that I needed to group the data by gender and mental health condition to properly display my intended visualization. This is shown in the difference from plot 1 to plot 2 because the data is grouped and summarized differently. Second, I changed the position of the bars from stacked to side-by-side so that comparisons within each gender were easier to see. This is shown in the difference from plot 2 to plot 3. Third, I flipped the coordinates of the graph so that the bars would be easier to read as well. I believe that the sideways bars are easier to compare than the vertical ones. This change is shown in the differences between plot 3 and plot 4. Fourth, I changed the single plot into a patchwork because I initially thought that creating an individual graph for each mental health condition would be helpful for gender comparisons. This change is seen from plot 4 to plot 5. However, I did not believe that this was the best way to visualize the data so I ended up changing it back for the final version. Fifth, I changed the color palette of the plot to a theme that was more accessible to colorblind individuals. This change is reflected in the final verson of the plot. Additionally, I also changed the titles of the plot, axes, and legend to be more clear. Sixth, I changed the ordering of the y-axis. The default order of the levels on the y-axis was alphabetical, but I thought it would be helpful to organize it by the gender with the greatest mental health condition presence (female) to the lowest presence (male). This gives a further general comparison that relates back to the main message of determining what groups are more likely to be affected by mental health conditions.

Question 3

I believe that the plot assigned to the variable “finalPlot” is the best version of the visualization that I am trying to create. First, I believe that this plot clearly shows how mental health conditions are broken down by gender. The plot is easy to read, the labels are clear, and the color theme is accessible for people who are colorblind. Additionally, there are certain features about the plot that demonstrate important features in the data. For example, the Gender axis is organized by the gender with the greatest presence of mental health conditions to the smallest presence of mental health conditions. Additionally, the bars are spaced appropriately within each gender so the viewer can see a clear comparison of the most prevalent mental health condition.

Sources Used

What color palettes are good for colorblind individuals?: https://davidmathlogic.com/colorblind/#%23648FFF-%23785EF0-%23DC267F-%23FE6100-%23FFB000

ChatGPT Prompt: What function can I use create a graph for one factor in a variable in R?

ChatGPT Prompt: What function can I use to reorder an axis from greatest to least?