Skip to content

Commit

Permalink
Merge pull request #4 from rossdrucker/issue-3/remove-caption-require…
Browse files Browse the repository at this point in the history
…ment

Fixes [#3](#3)
  • Loading branch information
rossdrucker committed Oct 3, 2021
2 parents 590206e + 1e6e6e9 commit f649a83
Show file tree
Hide file tree
Showing 42 changed files with 26 additions and 187 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## sportyR 1.0.4

- Removed requirement to include a plot caption color (fixes [#3](https://github.com/rossdrucker/sportyR/issues/3))

## sportyR 1.0.3

- Added tennis plotting capability
Expand Down
7 changes: 2 additions & 5 deletions R/baseball-mlb-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,6 @@ mlb_features_set_colors = function(infield_dirt_color = "#9b7653",
#' Create a ggplot2 instance that represents a regulation NBA court, with the
#' back tip of home plate corresponding to (0, 0)
#'
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#ffffff' (white)
#' @param background_color A hexadecimal string representing the color to use
#' for the plot's background. Default: '#395d33' (green)
#' @param unit A string indicating the units with which to make the plot.
Expand All @@ -503,8 +501,7 @@ mlb_features_set_colors = function(infield_dirt_color = "#9b7653",
#' colors to pass to the \code{mlb_features_set_colors()} function
#'
#' @return A ggplot2 instance that represents a regulation NBA court
geom_mlb = function(caption_color = "#707372",
background_color = "#395d33",
geom_mlb = function(background_color = "#395d33",
unit = "ft",
...) {
# Force the plot unit to be lower case
Expand Down Expand Up @@ -541,7 +538,7 @@ geom_mlb = function(caption_color = "#707372",
}

# Create the initial ggplot2 instance onto which the features will be added
g = create_plot_base(rotate = FALSE, caption_color, background_color)
g = create_plot_base(rotate = FALSE, background_color)

# Add the features to the ggplot2 instance
g = add_feature(g, infield_dirt$infield_dirt, color_list$infield_dirt_color)
Expand Down
5 changes: 1 addition & 4 deletions R/basketball-fiba-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -1383,8 +1383,6 @@ fiba_features_set_colors = function(court_background_color = "#d2ab6f",
#' representation. Default: \code{'ccw'}
#' @param unit A string indicating the units with which to make the plot.
#' Default: \code{'m'}
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#707372' (grey)
#' @param background_color A hexadecimal string representing the color to use for
#' the plot's background. Default: \code{NULL}
#' @param ... Additional arguments to pass to the function. These should be the
Expand All @@ -1395,7 +1393,6 @@ geom_fiba = function(full_surf = TRUE,
rotate = FALSE,
rotation_dir = "ccw",
unit = "m",
caption_color = "#707372",
background_color = NULL,
...) {
# Force the plot unit to be lower case
Expand Down Expand Up @@ -1453,7 +1450,7 @@ geom_fiba = function(full_surf = TRUE,
}

# Create the initial ggplot2 instance onto which the features will be added
g = create_plot_base(rotate, caption_color, background_color)
g = create_plot_base(rotate, background_color)

# Add the features to the ggplot2 instance
g = add_feature(g, court_background, color_list$court_background_color)
Expand Down
5 changes: 1 addition & 4 deletions R/basketball-nba-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -2159,8 +2159,6 @@ nba_features_set_colors = function(court_background_color = "#d2ab6f",
#' @param include_amateur_free_throw_lane_lines A boolean indicating whether or
#' not to include the amateur (NCAA) free-throw lane lines in the final plot.
#' Default: \code{TRUE}
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#707372' (grey)
#' @param background_color A hexadecimal string representing the color to use
#' for the plot's background. Default: \code{NULL}
#' @param ... Additional arguments to pass to the function. These should be the
Expand All @@ -2173,7 +2171,6 @@ geom_nba = function(full_surf = TRUE,
unit = "ft",
include_amateur_free_throw_lane = TRUE,
include_amateur_free_throw_lane_lines = TRUE,
caption_color = "#707372",
background_color = NULL,
...) {
# Force the plot unit to be lower case
Expand Down Expand Up @@ -2265,7 +2262,7 @@ geom_nba = function(full_surf = TRUE,
}

# Create the initial ggplot2 instance onto which the features will be added
g = create_plot_base(rotate, caption_color, background_color)
g = create_plot_base(rotate, background_color)

# Add the features to the ggplot2 instance
g = add_feature(g, court_background, color_list$court_background_color)
Expand Down
5 changes: 1 addition & 4 deletions R/basketball-ncaa-bb-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -1864,8 +1864,6 @@ ncaa_bb_features_set_colors = function(court_background_color = "#d2ab6f",
#' @param include_professional_free_throw_lane_lines A boolean indicating
#' whether or not to include the professional((W)NBA) free-throw lane lines in
#' the final plot. Default: \code{FALSE}
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#707372' (grey)
#' @param background_color A hexadecimal string representing the color to use
#' for the plot's background. Default: \code{NULL}
#' @param ... Additional arguments to pass to the function. These should be the
Expand All @@ -1880,7 +1878,6 @@ geom_ncaa_bb = function(full_surf = TRUE,
include_w_three_point_line = TRUE,
include_professional_free_throw_lane = FALSE,
include_professional_free_throw_lane_lines = FALSE,
caption_color = "#707372",
background_color = NULL,
...) {
# Force the plot unit to be lower case
Expand Down Expand Up @@ -1963,7 +1960,7 @@ geom_ncaa_bb = function(full_surf = TRUE,
}

# Create the initial ggplot2 instance onto which the features will be added
g = create_plot_base(rotate, caption_color, background_color)
g = create_plot_base(rotate, background_color)

# Add the features to the ggplot2 instance
g = add_feature(g, court_background, color_list$court_background_color)
Expand Down
5 changes: 1 addition & 4 deletions R/basketball-wnba-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -2153,8 +2153,6 @@ wnba_features_set_colors = function(court_background_color = "#d2ab6f",
#' @param include_amateur_free_throw_lane_lines A boolean indicating whether or
#' not to include the amateur (NCAA) free-throw lane lines in the final plot.
#' Default: \code{TRUE}
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#707372' (grey)
#' @param background_color A hexadecimal string representing the color to use
#' for the plot's background. Default: \code{NULL}
#' @param ... Additional arguments to pass to the function. These should be the
Expand All @@ -2167,7 +2165,6 @@ geom_wnba = function(full_surf = TRUE,
unit = "ft",
include_amateur_free_throw_lane = TRUE,
include_amateur_free_throw_lane_lines = TRUE,
caption_color = "#707372",
background_color = NULL,
...) {
# Force the plot unit to be lower case
Expand Down Expand Up @@ -2259,7 +2256,7 @@ geom_wnba = function(full_surf = TRUE,
}

# Create the initial ggplot2 instance onto which the features will be added
g = create_plot_base(rotate, caption_color, background_color)
g = create_plot_base(rotate, background_color)

# Add the features to the ggplot2 instance
g = add_feature(g, court_background, color_list$court_background_color)
Expand Down
5 changes: 1 addition & 4 deletions R/football-cfl-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,6 @@ cfl_features_set_colors = function(grass_color = "#196f0c",
#' @param origin_bottom_left A boolean indicating whether or not to place the
#' origin at the bottom-left corner of the plot (where the dead_line meets the
#' sideline). Default: \code{TRUE}
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#707372' (grey)
#' @param background_color A hexadecimal string representing the color to use
#' for the plot's background. Default: \code{NULL}
#' @param ... Additional arguments to pass to the function. These should be the
Expand All @@ -934,7 +932,6 @@ geom_cfl = function(full_surf = TRUE,
rotation_dir = "ccw",
unit = "yd",
origin_bottom_left = TRUE,
caption_color = "#707372",
background_color = NULL,
...) {
# Force the plot unit to be lower case
Expand Down Expand Up @@ -994,7 +991,7 @@ geom_cfl = function(full_surf = TRUE,
}

# Create the initial ggplot2 instance onto which the features will be added
g = create_plot_base(rotate, caption_color, background_color)
g = create_plot_base(rotate, background_color)

# Add the features to the ggplot2 instance
g = add_feature(g, grass, color_list$grass_color)
Expand Down
5 changes: 1 addition & 4 deletions R/football-ncaa-football-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,6 @@ ncaa_football_features_set_colors = function(grass_color = "#196f0c",
#' @param origin_bottom_left A boolean indicating whether or not to place the
#' origin at the bottom-left corner of the plot (where the endline meets the
#' sideline). Default: \code{TRUE}
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#707372' (grey)
#' @param background_color A hexadecimal string representing the color to use
#' for the plot's background. Default: \code{NULL}
#' @param ... Additional arguments to pass to the function. These should be the
Expand All @@ -988,7 +986,6 @@ geom_ncaa_football = function(full_surf = TRUE,
rotation_dir = "ccw",
unit = "yd",
origin_bottom_left = TRUE,
caption_color = "#707372",
background_color = NULL,
...) {
# Force the plot unit to be lower case
Expand Down Expand Up @@ -1051,7 +1048,7 @@ geom_ncaa_football = function(full_surf = TRUE,
}

# Create the initial ggplot2 instance onto which the features will be added
g = create_plot_base(rotate, caption_color, background_color)
g = create_plot_base(rotate, background_color)

# Add the features to the ggplot2 instance
g = add_feature(g, grass, color_list$grass_color)
Expand Down
5 changes: 1 addition & 4 deletions R/football-nfl-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,6 @@ nfl_features_set_colors = function(grass_color = "#196f0c",
#' @param origin_bottom_left A boolean indicating whether or not to place the
#' origin at the bottom-left corner of the plot (where the endline meets the
#' sideline). Default: \code{TRUE}
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#707372' (grey)
#' @param background_color A hexadecimal string representing the color to use
#' for the plot's background. Default: \code{NULL}
#' @param ... Additional arguments to pass to the function. These should be the
Expand All @@ -986,7 +984,6 @@ geom_nfl = function(full_surf = TRUE,
rotation_dir = "ccw",
unit = "yd",
origin_bottom_left = TRUE,
caption_color = "#707372",
background_color = NULL,
...) {
# Force the plot unit to be lower case
Expand Down Expand Up @@ -1050,7 +1047,7 @@ geom_nfl = function(full_surf = TRUE,
}

# Create the initial ggplot2 instance onto which the features will be added
g = create_plot_base(rotate, caption_color, background_color)
g = create_plot_base(rotate, background_color)

# Add the features to the ggplot2 instance
g = add_feature(g, grass, color_list$grass_color)
Expand Down
5 changes: 1 addition & 4 deletions R/hockey-iihf-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,6 @@ iihf_features_set_colors = function(boards_color = "#000000",
#' representation. Default: \code{'ccw'}
#' @param unit A string indicating the units with which to make the plot.
#' Default: \code{'m'}
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#707372' (grey)
#' @param background_color A hexadecimal string representing the color to use
#' for the plot's background. Default: \code{NULL}
#' @param ... Additional arguments to pass to the function. These should be the
Expand All @@ -1194,7 +1192,6 @@ geom_iihf = function(full_surf = TRUE,
rotate = FALSE,
rotation_dir = "ccw",
unit = "m",
caption_color = "#707372",
background_color = NULL,
...) {
# Faceoff spot centers for a half-sheets. These can be reflected over the y
Expand Down Expand Up @@ -1257,7 +1254,7 @@ geom_iihf = function(full_surf = TRUE,
}

# Create the initial ggplot2 instance onto which the features will be added
g = create_plot_base(rotate, caption_color, background_color)
g = create_plot_base(rotate, background_color)

# Add the features to the ggplot2 instance
g = add_feature(g, boards, color_list$boards_color)
Expand Down
5 changes: 1 addition & 4 deletions R/hockey-ncaa-hockey-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -1161,8 +1161,6 @@ ncaa_hockey_features_set_colors = function(boards_color = "#000000",
#' representation. Default: \code{'ccw'}
#' @param unit A string indicating the units with which to make the plot.
#' Default: \code{'ft'}
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#707372' (grey)
#' @param background_color A hexadecimal string representing the color to use
#' for the plot's background. Default: \code{NULL}
#' @param ... Additional arguments to pass to the function. These should be the
Expand All @@ -1173,7 +1171,6 @@ geom_ncaa_hockey = function(full_surf = TRUE,
rotate = FALSE,
rotation_dir = "ccw",
unit = "ft",
caption_color = "#707372",
background_color = NULL,
...) {
# Faceoff spot centers for a half-sheets. These can be reflected over the y
Expand Down Expand Up @@ -1236,7 +1233,7 @@ geom_ncaa_hockey = function(full_surf = TRUE,
}

# Create the initial ggplot2 instance onto which the features will be added
g = create_plot_base(rotate, caption_color, background_color)
g = create_plot_base(rotate, background_color)

# Add the features to the ggplot2 instance
g = add_feature(g, boards, color_list$boards_color)
Expand Down
5 changes: 1 addition & 4 deletions R/hockey-nhl-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -1232,8 +1232,6 @@ nhl_features_set_colors = function(boards_color = "#000000",
#' representation. Default: \code{'ccw'}
#' @param unit A string indicating the units with which to make the plot.
#' Default: \code{'ft'}
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#707372' (grey)
#' @param background_color A hexadecimal string representing the color to use
#' for the plot's background. Default: \code{NULL}
#' @param ... Additional arguments to pass to the function. These should be the
Expand All @@ -1244,7 +1242,6 @@ geom_nhl = function(full_surf = TRUE,
rotate = FALSE,
rotation_dir = "ccw",
unit = "ft",
caption_color = "#707372",
background_color = NULL,
...) {
# Faceoff spot centers for a half-sheets. These can be reflected over the y
Expand Down Expand Up @@ -1309,7 +1306,7 @@ geom_nhl = function(full_surf = TRUE,
}

# Create the initial ggplot2 instance onto which the features will be added
g = create_plot_base(rotate, caption_color, background_color)
g = create_plot_base(rotate, background_color)

# Add the features to the ggplot2 instance
g = add_feature(g, boards, color_list$boards_color)
Expand Down
5 changes: 1 addition & 4 deletions R/hockey-nwhl-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,6 @@ nwhl_features_set_colors = function(boards_color = "#000000",
#' representation. Default: \code{'ccw'}
#' @param unit A string indicating the units with which to make the plot.
#' Default: \code{'ft'}
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#707372' (grey)
#' @param background_color A hexadecimal string representing the color to use
#' for the plot's background. Default: \code{NULL}
#' @param ... Additional arguments to pass to the function. These should be the
Expand All @@ -1252,7 +1250,6 @@ geom_nwhl = function(full_surf = TRUE,
rotate = FALSE,
rotation_dir = "ccw",
unit = "ft",
caption_color = "#707372",
background_color = NULL,
...) {
# Faceoff spot centers for a half-sheets. These can be reflected over the y
Expand Down Expand Up @@ -1317,7 +1314,7 @@ geom_nwhl = function(full_surf = TRUE,
}

# Create the initial ggplot2 instance onto which the features will be added
g = create_plot_base(rotate, caption_color, background_color)
g = create_plot_base(rotate, background_color)

# Add the features to the ggplot2 instance
g = add_feature(g, boards, color_list$boards_color)
Expand Down
16 changes: 0 additions & 16 deletions R/plot-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
#'
#' @param rotate Whether or not the final output will be rotated (adjusts the
#' margins). Default: \code{FALSE}
#' @param caption_color A hexadecimal string representing the color to use for
#' the plot's caption. Default: '#707372' (grey)
#' @param background_color A hexadecimal string representing the color to use for
#' the plot's background. Default: \code{NULL}
#'
#' @return A ggplot2 instance onto which the features will be added
create_plot_base = function(rotate = FALSE,
caption_color = "#707372",
background_color = NULL) {
if (is.null(caption_color)) {
# Ensure that the caption color is provided
stop("Caption color must not be NULL")
}

if (!is.null(background_color)) {
# If the plot has a specific background color, set the element correctly
background = ggplot2::element_rect(fill = background_color)
Expand All @@ -30,35 +22,27 @@ create_plot_base = function(rotate = FALSE,
g = ggplot2::ggplot() +
ggplot2::coord_fixed() +
ggplot2::theme(
plot.caption = ggplot2::element_text(color = caption_color, hjust = 0.5),
plot.margin = ggplot2::margin(0, -1, 0, -1, "cm"),
panel.border = ggplot2::element_blank(),
panel.background = background,
axis.title = ggplot2::element_blank(),
axis.text = ggplot2::element_blank(),
axis.ticks = ggplot2::element_blank(),
panel.grid = ggplot2::element_blank(),
) +
ggplot2::labs(
caption = "Plot made via sportyR"
)
}

else {
g = ggplot2::ggplot() +
ggplot2::coord_fixed() +
ggplot2::theme(
plot.caption = ggplot2::element_text(color = caption_color, hjust = 0.5),
plot.margin = ggplot2::margin(-1, 0, -1, 0, "cm"),
panel.border = ggplot2::element_blank(),
panel.background = background,
axis.title = ggplot2::element_blank(),
axis.text = ggplot2::element_blank(),
axis.ticks = ggplot2::element_blank(),
panel.grid = ggplot2::element_blank(),
) +
ggplot2::labs(
caption = "Plot made via sportyR"
)
}

Expand Down
Loading

0 comments on commit f649a83

Please sign in to comment.