library(ggplot2)
dodgers <- read.csv("DodgersData.csv")
# Calculate attendance statistics
median(dodgers$attend)
## [1] 40284
mean(dodgers$attend)
## [1] 41040.07
# Histogram of attendance
histogram <- ggplot(dodgers, aes(x = attend)) +
geom_histogram(
binwidth = 5000,
fill = "dodgerblue",
color = "white"
) +
labs(
title = "Distribution of Dodgers Game Attendance",
x = "Attendance",
y = "Number of Games"
) +
theme_minimal()
print(histogram)
# Scatter plot of attendance and temperature
scatterplot <- ggplot(dodgers, aes(x = temp, y = attend)) +
geom_point(color = "darkgreen", size = 3) +
geom_smooth(method = "lm", se = FALSE, color = "red") +
labs(
title = "Dodgers Attendance and Game Temperature",
x = "Temperature",
y = "Attendance"
) +
theme_minimal()
print(scatterplot)
## `geom_smooth()` using formula = 'y ~ x'
```
Question 1: The median attendance was 40,284 people, and the mean attendance was approximately 41,040. I would use the median to describe a typical game because some games had unusually high attendance, which increases the mean. The median better represents attendance at a normal Dodgers game.
Question 2: Attendance ranged from 24,312 to 56,000 people. Most games had around 40,000 attendees, while several games had attendance above 50,000.
Question 3: The scatter plot shows little relationship between temperature and attendance. The points are widely scattered. This suggests that temperature alone was not a strong predictor of attendance.