mlbbat10 | R Documentation |
Major League Baseball Player Hitting Statistics for 2010.
mlbbat10
A data frame with 1199 observations on the following 19 variables.
Player name
Team abbreviation
Player position
Number of games
Number of at bats
Number of runs
Number of hits
Number of doubles
Number of triples
Number of home runs
Number of runs batted in
Total bases, computed as 3HR + 23B + 1*2B + H
Number of walks
Number of strikeouts
Number of stolen bases
Number of times caught stealing
On base percentage
Slugging percentage (total_base / at_bat)
Batting average
https://www.mlb.com, retrieved 2011-04-22.
library(ggplot2)
library(dplyr)
library(scales)
mlbbat10_200 <- mlbbat10 |>
filter(mlbbat10$at_bat > 200)
# On-base percentage across positions
ggplot(mlbbat10_200, aes(x = position, y = obp, fill = position)) +
geom_boxplot(show.legend = FALSE) +
scale_y_continuous(labels = label_number(suffix = "%", accuracy = 0.01)) +
labs(
title = "On-base percentage across positions",
y = "On-base percentage across positions",
x = "Position"
)
# Batting average across positions
ggplot(mlbbat10_200, aes(x = bat_avg, fill = position)) +
geom_density(alpha = 0.5) +
labs(
title = "Batting average across positions",
fill = NULL,
y = "Batting average",
x = "Position"
)
# Mean number of home runs across positions
mlbbat10_200 |>
group_by(position) |>
summarise(mean_home_run = mean(home_run)) |>
ggplot(aes(x = position, y = mean_home_run, fill = position)) +
geom_col(show.legend = FALSE) +
labs(
title = "Mean number of home runs across positions",
y = "Home runs",
x = "Position"
)
# Runs batted in across positions
ggplot(mlbbat10_200, aes(x = run, y = obp, fill = position)) +
geom_boxplot(show.legend = FALSE) +
labs(
title = "Runs batted in across positions",
y = "Runs",
x = "Position"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.