Assignment 0HV130 - Data Visualizations

1801511 and 1746936

Author

15

Part 1 - Inspecting Frequencies

Bar Chart for Chronotype Frequency

ggplot(df_clean, aes(x = Chronotype, fill=Chronotype)) +
  geom_bar(color = "black")+ 
  theme_minimal() +
  scale_fill_brewer(palette = "Set2") +  # Softer colors
  labs(title = "Distribution of Chronotype", x = "Chronotype", y = "Count") +
  theme(text = element_text(size = 14), legend.position = "none")

Summary: The bar chart shows the distribution of Chronotype categories. The aesthetics were adjusted with a color palatte fill, black outline, and minimal theme for clarity.

Stacked Histogram for PSQI_GlobalScore by Chronotype

ggplot(df_clean, aes(x = PSQI_GlobalScore, fill = Chronotype)) +
  geom_histogram(binwidth = 1, color = "black", position = "stack") +
  scale_x_continuous(breaks = seq(1, 14, 1), labels = 1:14) +
  labs(title = "Sleep Disturbances by Chronotype", x = "Disturbances in Sleep Quality", y = "Count") +
  theme_minimal()+
  scale_fill_brewer(palette = "Set2") 

Stacked Histogram with Proportions

ggplot(df_clean, aes(x = PSQI_GlobalScore, fill = Chronotype)) +
  geom_histogram(binwidth = 1, color = "black", position = "fill") +
  scale_x_continuous(breaks = seq(1, 14, 1), labels = 1:14) +
  labs(title = "Proportion of Chronotype in Sleep Quality Scores", x = "Disturbances in Sleep Quality", y = "Proportion") +
  theme_minimal() +
  scale_fill_brewer(palette = "Set2") 

Combined Histogram using Patchwork

stacked_hist <- ggplot(df_clean, aes(x = PSQI_GlobalScore, fill = Chronotype)) +
  geom_histogram(binwidth = 1, color = "black", position = "stack") +
  theme_minimal() +
  scale_fill_brewer(palette = "Set2") +
  labs(title = "Stacked Histogram")

proportional_hist <- ggplot(df_clean, aes(x = PSQI_GlobalScore, fill = Chronotype)) +
  geom_histogram(binwidth = 1, color = "black", position = "fill") +
  theme_minimal() +
  scale_fill_brewer(palette = "Set2") +
  labs(title = "Proportional Histogram")

stacked_hist + proportional_hist

Summary: The first histogram shows absolute frequencies, while the second presents proportions. This helps in comparing distributions across Chronotypes.

Part 2 - Mapping Two Numerical Variables

Scatter Plot with Chronotype Color Coding

scatter1 <- ggplot(df_clean, aes(x = PSQI_GlobalScore, y = Conscientiousness, color = Chronotype, shape = Chronotype)) +
  geom_point(alpha = 0.6, size = 3, position = position_jitter(width = 0.2, height = 0.2)) +
  scale_color_brewer(palette = "Set2") +
  labs(title = "Scatterplot of Sleep Quality vs Conscientiousness", x = "PSQI Global Score", y = "Conscientiousness") +
  theme_minimal()

Scatter Plot Faceted by Chronotype with Regression Line

scatter2 <- ggplot(df_clean, aes(x = PSQI_GlobalScore, y = Conscientiousness)) +
  geom_point(alpha = 0.6, size = 2) +
  geom_smooth(method = "lm", color = "red", se = FALSE) +
  facet_wrap(~ Chronotype) +
  scale_color_brewer(palette = "Set2") +
  theme_minimal() +
  labs(title = "Regression by Chronotype", x = "PSQI Global Score", y = "Conscientiousness")

Combined Scatter Plots

scatter1 + scatter2 + plot_layout(ncol = 1)
`geom_smooth()` using formula = 'y ~ x'

Summary: The first plot shows a general relationship, while the second highlights trends by Chronotype. The regression lines help identify patterns.

Part 3 - Combo Plots (Raincloud Plot)

Data Reshaping for Big Five Scores

var_BigFive <- c("Extraversion", "Agreeableness", "Conscientiousness", "Neuroticism", "Openness")
df_BigFive_long <- df_clean %>%
  select(ID, all_of(var_BigFive)) %>%
  pivot_longer(-ID, names_to = "BigFiveDimension", values_to = "value")

Raincloud Plot

ggplot(df_BigFive_long, aes(x = BigFiveDimension, y = value, fill = BigFiveDimension)) +
  stat_halfeye(justification = -0.2, adjust = 0.6, width = 0.7, .width = 0, point_colour = NA) +
  geom_boxplot(width = 0.2, outlier.color = NA, alpha = 0.5) +
  stat_dots(side = "left") +
  scale_fill_brewer(palette = "Set2") +
  coord_flip() +
  labs(title = "Raincloud Plot of Big Five Scores", x = "Personality Dimension", y = "Score") +
  theme_minimal()

Summary: The raincloud plot displays individual observations, distributions, and summary statistics. Adjustments were made to width, transparency, and justification for clarity.