Week 8 Assignment

Author

xutong

Published

October 22, 2023

#Intro This project will look at a dataset about human heights. Specifically, I want to investigate the distribution of heights among males and females.

#Libraries

library(dslabs)
library(ggplot2)

#Load the movies dataset
data("heights")

#Plotting the data to visualize I will start by making a scatter plot to show the distribution of heights among males and females.

# Define the base plot
p <- ggplot(heights, aes(x = height, color = sex)) +
  
  # Adding the data points
  geom_density(alpha = 0.6) +

  # Add labels and titles
  labs(
    title = "Distribution of Heights Among Males and Females",
    x = "Height in Inches",
    y = "Density",
    color = "Gender"
  ) +
  
  # Apply a theme
  theme_minimal() +
  
  # Position the legend
  theme(legend.position = "top")
  
# Create the plot
print(p)

This graph shows the distribution of heights for males and females. The x-axis represents height in inches, while the y-axis represents the density of individuals at each height. The color indicates the gender, either “Male” or “Female”. The graph is designed to be simple and easy to read.