Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyelhabr committed Feb 12, 2024
1 parent 8fdc79c commit c255517
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.Rdata
docs
inst/doc
docs/
58 changes: 37 additions & 21 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ 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)
Expand All @@ -46,7 +48,7 @@ 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 +82,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}"
)
```
58 changes: 38 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pak::pak("tonyelhabr/soccerplotR")

## Examples

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

``` r
library(soccerplotR)
library(ggplot2)
Expand All @@ -42,7 +45,7 @@ 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 +79,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
Binary file modified man/figures/README-example-1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-example-2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c255517

Please sign in to comment.