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 theme_animalcrossing() #1

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Binary file added .DS_Store
Binary file not shown.
512 changes: 512 additions & 0 deletions .Rhistory

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@ export(scale_fill_fairyfloss)
export(scale_fill_sugarpill)
export(theme_fairyfloss)
export(theme_sugarpill)


importFrom(ggplot2,discrete_scale)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_line)
122 changes: 122 additions & 0 deletions R/animalcrossing.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#' animalcrossing theme
#'
#' A ggplot2 theme based off \href{https://www.canva.com/colors/color-palette-generator/}{Canva}'s palette generator.
#' Palette generated on image of Nintendo Switch Animal Crossing New Horizons special edition.
#'
#' @inheritParams ggplot2::theme_grey
#'
#' @rdname theme_animalcrossing
#' @export
#'
#' @examples
#' library(ggplot2)
#' ggplot(nintendo_sales, aes(x = sales_million, y = console)) +
#' geom_col() +
#' facet_wrap(~sales_type) +
#' theme_animalcrossing()
#' @importFrom ggplot2 element_rect element_line element_text element_blank theme theme_grey
#'
theme_animalcrossing <- function(base_size = 16, base_line_size = base_size / 22, base_rect_size = base_size / 22) {
theme_grey(base_size = base_size, base_family = "Helvetica", base_line_size, base_rect_size) +
theme(
plot.background = element_rect(fill = animalcrossing_col("beige"), colour = animalcrossing_col("sky_blue")),
panel.background = element_rect(fill = animalcrossing_col("dark_sea_green")),
panel.grid.major = element_line(colour = animalcrossing_col("peru")),
panel.grid.minor = element_blank(),
axis.ticks = element_line(colour = animalcrossing_col("peru")),
axis.text = element_text(colour = animalcrossing_col("sienna")),
axis.title = element_text(colour = animalcrossing_col("dark_slate")),
plot.title = element_text(colour = animalcrossing_col("dark_slate"), hjust = 0.5),
plot.subtitle = element_text(colour = animalcrossing_col("sienna"), hjust = 0.5),
legend.background = element_rect(fill = NA, colour = animalcrossing_col("beige")),
legend.title = element_text(colour = animalcrossing_col("sienna")),
legend.text = element_text(colour = animalcrossing_col("sienna")),
legend.key = element_rect(fill = NA),
strip.background = element_rect(fill = animalcrossing_col("sienna")),
strip.text = element_text(colour = animalcrossing_col("beige"))
)
}

#' Animal Crossing color scale
#'
#' @param discrete Whether the colour aesthetic is discrete or not
#' @param reverse Whether the palette should be reversed
#' @param ... Additional arguments
#'
#' @rdname scale_colour_animalcrossing
#' @export
#'
#' @examples
#' library(ggplot2)
#' ggplot(nintendo_sales, aes(x = sales_million, y = console, colour = sales_type)) +
#' geom_point() +
#' scale_color_animalcrossing() +
#' theme_animalcrossing()
#' @importFrom ggplot2 discrete_scale scale_color_gradientn
scale_colour_animalcrossing <- function(discrete = TRUE, reverse = FALSE, ...) {
pal <- animalcrossing_pal(reverse = reverse)

if (discrete) {
discrete_scale("colour", "animalcrossing", palette = pal, ...)
} else {
scale_color_gradientn(colours = pal(256), ...)
}
}

#' Animal Crossing fill scale
#'
#' @inheritParams scale_colour_animalcrossing
#'
#' @export
#'
#' @examples
#' library(ggplot2)
#' ggplot(nintendo_sales, aes(x = sales_million, y = console, fill = sales_type)) +
#' geom_col() +
#' scale_fill_animalcrossing() +
#' theme_animalcrossing()
#' @importFrom ggplot2 discrete_scale scale_fill_gradientn
scale_fill_animalcrossing <- function(discrete = TRUE, reverse = FALSE, ...) {
pal <- animalcrossing_pal(reverse = reverse)

if (discrete) {
discrete_scale("fill", "animalcrossing", palette = pal, ...)
} else {
scale_fill_gradientn(colours = pal(256), ...)
}
}

#' @importFrom grDevices colorRampPalette
animalcrossing_pal <- function(reverse = FALSE, ...) {
pal <- animalcrossing_col()
pal <- pal[!(names(pal) %in% c("dark_purple", "light_purple", "white"))]

if (reverse) {
pal <- rev(pal)
}
colorRampPalette(pal, ...)
}

#' @export
#' @rdname scale_colour_animal_crossing
scale_color_animalcrossing <- scale_colour_animalcrossing

animalcrossing_col <- function(...) {
cols <- c(...)

if (is.null(cols)) {
return(animalcrossing_colours)
}

animalcrossing_colours[cols]
}

animalcrossing_colours <-
c(
sky_blue = "#8EDCE6",
beige = "#F5EADD",
dark_slate = "#2F3939",
dark_sea_green = "#A0CDA2",
sienna = "#78512C",
peru = "#C6923C"
)
47 changes: 45 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ ggplot(nintendo_sales, aes(x = sales_million, y = console)) +
theme_fairyfloss()
```

It's probably (definitely) not a complete theme but at least it's cute `r emo::ji("cloud")`
It's probably (definitely) not a complete theme but at least it's cute `r` `emo::ji("cloud")`

There is a colour palette built in:

@@ -100,7 +100,7 @@ library(dplyr)
library(forcats)
nintendo_sales %>%
mutate(console = fct_lump_n(console, n = 8, w = sales_million, other_level = "Other Consoles")) %>%
mutate(console = fct_lump(console, n = 8, w = sales_million, other_level = "Other Consoles")) %>%
group_by(console, sales_type) %>%
summarise(sales_million = sum(sales_million)) %>%
ungroup() %>%
@@ -117,6 +117,49 @@ nintendo_sales %>%
theme(legend.position = "none")
```

## animalcrossing
`theme_animalcrossing()` is a ggplot2 theme based off a palette generator
[Canva](https://www.canva.com/colors/color-palette-generator/). Palette generated on image of a Nintendo Switch Animal Crossing New Horizons special edition. You can use this to do things like plot out how many bells you owe Tom Nook!

![](https://animalcrossingworld.com/wp-content/uploads/2020/01/special-edition-animal-crossing-new-horizons-nintendo-switch-standalone-parts-banner.jpg)

```{r}
ggplot(nintendo_sales, aes(x = console, y = sales_million)) +
geom_col(fill = animalcrossing_colours["sky_blue"],
color = animalcrossing_colours["dark_slate"]) +
facet_wrap(~sales_type)+
theme_animalcrossing() +
coord_flip() +
labs(title = "Nintendo Sales",
subtitle = "Hardware vs. Software")
```

Below is the palette the package uses! Maybe we can add more colors from characters (Tom Nook, Blathers, Gulliver, etc.)

```{r}
library(scales)
show_col(animalcrossing_colours)
```

Here is another example:

```{r}
ggplot(nintendo_sales, aes(x = sales_type, y = sales_million, fill = sales_type))+
geom_boxplot()+
geom_jitter(color = animalcrossing_colours["dark_slate"])+
scale_fill_animalcrossing(discrete = T)+
theme_animalcrossing() +
coord_flip() +
labs(title = "Nintendo Sales",
subtitle = "Hardware vs. Software",
y = "Sales (Millions)",
x = "Type",
fill = "")
```



## Data

`ggcute` comes with one data set built in, Nintendo sales as of December 31, 2019:
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -126,6 +126,52 @@ nintendo_sales %>%

<img src="man/figures/README-unnamed-chunk-7-1.png" width="75%" />

## animalcrossing
`theme_animalcrossing()` is a ggplot2 theme based off a palette generator
[Canva](https://www.canva.com/colors/color-palette-generator/). Palette generated on image of a Nintendo Switch Animal Crossing New Horizons special edition. You can use this to do things like plot out how many bells you owe Tom Nook!

<img src="man/figures/README-unnamed-chunk-8-2.png" width="75%" />


```{r}
ggplot(nintendo_sales, aes(x = console, y = sales_million)) +
geom_col(fill = animalcrossing_colours["sky_blue"],
color = animalcrossing_colours["dark_slate"]) +
facet_wrap(~sales_type)+
theme_animalcrossing() +
coord_flip() +
labs(title = "Nintendo Sales",
subtitle = "Hardware vs. Software")
```
<img src="man/figures/README-unnamed-chunk-8-1.png" width="75%" />

Below is the palette the package uses! Maybe we can add more colors from characters (Tom Nook, Blathers, Gulliver, etc.)

``` r
library(scales)

show_col(ggcute:::animalcrossing_colours)
```
<img src="man/figures/README-unnamed-chunk-9-1.png" width="75%" />

Here is another example:

```{r}
ggplot(nintendo_sales, aes(x = sales_type, y = sales_million, fill = sales_type))+
geom_boxplot()+
geom_jitter(color = animalcrossing_colours["dark_slate"])+
scale_fill_animalcrossing(discrete = T)+
theme_animalcrossing() +
coord_flip() +
labs(title = "Nintendo Sales",
subtitle = "Hardware vs. Software",
y = "Sales (Millions)",
x = "Type",
fill = "")
```
<img src="man/figures/README-unnamed-chunk-10-1.png" width="75%" />


## Data

`ggcute` comes with one data set built in, Nintendo sales as of December
Binary file modified data/nintendo_sales.rda
Binary file not shown.
Binary file added man/.DS_Store
Binary file not shown.
Binary file added man/figures/.DS_Store
Binary file not shown.
Binary file added man/figures/README-unnamed-chunk-10-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-unnamed-chunk-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.
Binary file modified man/figures/README-unnamed-chunk-3-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-unnamed-chunk-4-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-unnamed-chunk-5-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-unnamed-chunk-6-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-unnamed-chunk-7-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 added man/figures/README-unnamed-chunk-8-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 added man/figures/README-unnamed-chunk-8-2.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 added man/figures/README-unnamed-chunk-9-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions man/scale_colour_animalcrossing.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions man/scale_fill_animalcrossing.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions man/theme_animalcrossing.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.