data <- read.csv("DodgersData.csv")
What is the median value of attendance? What is the mean value of attendance? Which value would you use for interpretation purposes? Why?
Mean <- mean(data$attend)
Median <- median(data$attend)
Mean
## [1] 41040.07
Median
## [1] 40284
The mean attendance is about 41,040, while the median is 40,284. I would use the median because it is less affected by unusually high or low attendance.
Draw a graph with the ggplot package by following the example covered in Lab 4.
library(ggplot2)
ggplot(data, aes(x = attend)) +
geom_histogram(
binwidth = 5000,
color = "black",
fill = "lightblue"
) +
labs(
title = "Distribution of Dodgers Attendance",
x = "Attendance",
y = "Frequency"
) +
theme_minimal()
Most Dodgers games had about 35,000 to 45,000 fans, with a few games reaching over 50,000.
ggplot(data, aes(x = attend, fill = day_night)) +
geom_histogram(bins = 30, col = "white") +
scale_fill_manual(values = c("pink", "lightblue")) +
ggtitle("Frequency of Attendance - Day vs. Night Games") +
labs(
x = "Attendance",
y = "Frequency",
fill = "Game Time"
)
Night games occurred more often than day games. Attendance for both day and night games varied across the season.