Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add national teams #2

Merged
merged 5 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.Rhistory
.Rdata
docs
inst/doc
docs/
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: soccerplotR
Title: Soccer Logo Plots in 'ggplot2'
Version: 0.0.1
Version: 0.0.2
Authors@R:
person("Tony", "ElHabr", , "[email protected]", role = c("aut", "cre"))
Description: A set of functions to visualize professional soccer analysis in 'ggplot2'.
Expand All @@ -18,10 +18,13 @@ Imports:
rlang (>= 0.4.11),
scales (>= 1.1.0)
Suggests:
knitr,
purrr (>= 0.2.0),
rmarkdown,
testthat (>= 3.0.0)
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
VignetteBuilder: knitr
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# soccerplotR 0.0.2 (development)

- Adds national team logos [#1](https://github.com/tonyelhabr/soccerplotR/issues/1)
- Adds logos for club teams not appearing in the first and second tiers for their domestic league in 2023, but appearing in prior seasons.

# soccerplotR 0.0.1

- Initial version of the package, based heavily on `{nbaplotR} 0.0.4`

Binary file modified R/sysdata.rda
Binary file not shown.
59 changes: 38 additions & 21 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ pak::pak("tonyelhabr/soccerplotR")

## Examples

Using `all_valid_team_names`, `geom_soccer_logos`, and `scale_fill_soccer(color = "primary")`.

```{r example-1, fig.height=7, fig.width=7}
library(soccerplotR)
library(ggplot2)
library(showtext)

FONT <- "Kanit"
sysfonts::font_add_google(FONT)
showtext::showtext_auto()
showtext::showtext_opts(dpi = 300)

team_names <- unlist(unname(soccerplotR::all_valid_team_names()))
team_names <- unlist(unname(all_valid_team_names()))
set.seed(42)
sampled_team_names <- sample(team_names, size = 45)

Expand Down Expand Up @@ -80,42 +83,56 @@ ggplot(df) +
scale_fill_soccer(type = "primary") +
theme_void() +
theme(
plot.margin = margin(25, 25, 25, 25, "pt")
plot.margin = margin(25, 25, 25, 25, "pt"),
plot.title.position = "plot",
plot.title = element_text(family = FONT, size = 18, hjust = 0.5)
) +
coord_cartesian(clip = "off") +
labs(
title = "A random sample of 45 teams"
) +
theme(
plot.title.position = "plot",
plot.title = element_text(family = FONT, size = 18, hjust = 0.5)
)
```

```{r example-2, fig.height=10, fig.width=7.5}
team_names <- soccerplotR::valid_team_names("ENG")
Using `valid_team_names`, `scale_color_soccer(color = "secondary")`, and `scale_fill_soccer(color = "primary")`.

```{r example-2, fig.height=7, fig.width=7}
team_names <- valid_team_names("ENG")

df <- data.frame(
team_name = team_names,
value = 1:length(team_names)
a = rep(1:5, 9),
b = sort(rep(0:8, 5), decreasing = TRUE),
team_name = c(team_names, NA)
)

df$team_name <- factor(df$team_name, levels = df$team_name[order(df$value)])

ggplot(df, aes(y = team_name, x = value)) +
geom_col(aes(color = team_name, fill = team_name), width = 0.8) +
ggplot(df, aes(x = a, y = b)) +
geom_point(
aes(
color = team_name,
fill = team_name
),
shape = 21,
size = 12,
stroke = 3
) +
geom_text(
aes(
label = team_name
),
color = "black",
family = FONT,
size = 10 / .pt,
nudge_y = -0.5
) +
scale_color_soccer(type = "secondary") +
scale_fill_soccer(alpha = 0.8) +
theme_minimal() +
scale_fill_soccer(type = "primary", alpha = 0.8) +
theme_void() +
theme(
plot.margin = margin(25, 25, 25, 25, "pt"),
plot.title.position = "plot",
plot.title = element_text(family = FONT, size = 18),
axis.text = element_text(family = FONT),
panel.grid.major.y = element_blank()
plot.title = element_text(family = FONT, size = 18, hjust = 0.5)
) +
coord_cartesian(clip = "off") +
labs(
x = NULL,
y = NULL,
title = "English teams in {soccerplotR}"
)
```
59 changes: 39 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ pak::pak("tonyelhabr/soccerplotR")

## Examples

Using `all_valid_team_names`, `geom_soccer_logos`, and
`scale_fill_soccer(color = "primary")`.

``` r
library(soccerplotR)
library(ggplot2)
library(showtext)

FONT <- "Kanit"
sysfonts::font_add_google(FONT)
showtext::showtext_auto()
showtext::showtext_opts(dpi = 300)

team_names <- unlist(unname(soccerplotR::all_valid_team_names()))
team_names <- unlist(unname(all_valid_team_names()))
set.seed(42)
sampled_team_names <- sample(team_names, size = 45)

Expand Down Expand Up @@ -76,44 +80,59 @@ ggplot(df) +
scale_fill_soccer(type = "primary") +
theme_void() +
theme(
plot.margin = margin(25, 25, 25, 25, "pt")
plot.margin = margin(25, 25, 25, 25, "pt"),
plot.title.position = "plot",
plot.title = element_text(family = FONT, size = 18, hjust = 0.5)
) +
coord_cartesian(clip = "off") +
labs(
title = "A random sample of 45 teams"
) +
theme(
plot.title.position = "plot",
plot.title = element_text(family = FONT, size = 18, hjust = 0.5)
)
```

<img src="man/figures/README-example-1-1.png" width="100%" />

Using `valid_team_names`, `scale_color_soccer(color = "secondary")`, and
`scale_fill_soccer(color = "primary")`.

``` r
team_names <- soccerplotR::valid_team_names("ENG")
team_names <- valid_team_names("ENG")

df <- data.frame(
team_name = team_names,
value = 1:length(team_names)
a = rep(1:5, 9),
b = sort(rep(0:8, 5), decreasing = TRUE),
team_name = c(team_names, NA)
)

df$team_name <- factor(df$team_name, levels = df$team_name[order(df$value)])

ggplot(df, aes(y = team_name, x = value)) +
geom_col(aes(color = team_name, fill = team_name), width = 0.8) +
ggplot(df, aes(x = a, y = b)) +
geom_point(
aes(
color = team_name,
fill = team_name
),
shape = 21,
size = 12,
stroke = 3
) +
geom_text(
aes(
label = team_name
),
color = "black",
family = FONT,
size = 10 / .pt,
nudge_y = -0.5
) +
scale_color_soccer(type = "secondary") +
scale_fill_soccer(alpha = 0.8) +
theme_minimal() +
scale_fill_soccer(type = "primary", alpha = 0.8) +
theme_void() +
theme(
plot.margin = margin(25, 25, 25, 25, "pt"),
plot.title.position = "plot",
plot.title = element_text(family = FONT, size = 18),
axis.text = element_text(family = FONT),
panel.grid.major.y = element_blank()
plot.title = element_text(family = FONT, size = 18, hjust = 0.5)
) +
coord_cartesian(clip = "off") +
labs(
x = NULL,
y = NULL,
title = "English teams in {soccerplotR}"
)
```
Expand Down
Loading
Loading