Skip to content

Commit

Permalink
fix: flexoki example
Browse files Browse the repository at this point in the history
  • Loading branch information
hrbrmstr committed Jan 16, 2025
1 parent bbf3006 commit 2469415
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 46 deletions.
11 changes: 9 additions & 2 deletions R/flexoki.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ create_continuous_scale <- function(colors) {
#' geom_tile() +
#' scale_color_flexoki_continuous(palette = "blue")
scale_color_flexoki_continuous <- function(palette = "red", ...) {
scale_color_gradientn(colors = create_continuous_scale(flexoki_extended[[palette]])(100), ...)
scale_color_gradientn(
colors = create_continuous_scale(flexoki_extended[[palette]])(100),
...
)
}

#' Continuous Fill Scale Using Flexoki Colors
Expand All @@ -209,5 +212,9 @@ scale_color_flexoki_continuous <- function(palette = "red", ...) {
#' geom_tile() +
#' scale_fill_flexoki_continuous(palette = "blue")
scale_fill_flexoki_continuous <- function(palette = "red", ...) {
scale_fill_gradientn(colors = create_continuous_scale(flexoki_extended[[palette]])(100), ...)
scale_fill_gradientn(
colors = create_continuous_scale(
flexoki_extended[[palette]])(100),
...
)
}
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.re
[![Signed
by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr)
![Signed commit
%](https://img.shields.io/badge/Signed_Commits-3%25-lightgrey.svg)
%](https://img.shields.io/badge/Signed_Commits-4%25-lightgrey.svg)

[![cran
checks](https://cranchecks.info/badges/worst/hrbrthemes.png)](https://cranchecks.info/pkgs/hrbrthemes)
Expand Down Expand Up @@ -341,28 +341,32 @@ ggplot(mpg, aes(displ, hwy, color=class)) +
<img src="man/figures/README-flexoki2-1.png" width="672" />

``` r
# Continuous color scales
library(tidyr)

expand.grid(x=1:50, y=1:50) %>%
mutate(z = sqrt((x-25)^2 + (y-25)^2)) %>%
ggplot(aes(x, y, fill=z)) +
geom_tile() +
facet_wrap(~palette, ncol=4) +
scale_fill_flexoki_continuous() +
labs(title="Flexoki Continuous Color Scales",
subtitle="All 8 continuous color palettes",
caption="Using scale_fill_flexoki_continuous()") +
theme_ipsum(grid="") +
theme(legend.position="none") -> p

p %+% data.frame(
library(patchwork)

data.frame(
x = rep(1:50, 50),
y = rep(1:50, each=50),
z = sqrt((rep(1:50, 50)-25)^2 + (rep(1:50, each=50)-25)^2),
palette = factor(rep(c("red", "orange", "yellow", "green",
"cyan", "blue", "purple", "magenta"), each=2500))
)
z = sqrt((rep(1:50, 50)-25)^2 + (rep(1:50, each=50)-25)^2)
) -> grad_df

names(flexoki_dark) |>
map(\(.p) {
ggplot(grad_df, aes(x, y, fill=z)) +
geom_tile() +
scale_fill_flexoki_continuous(palette = .p) +
labs(
x = NULL, y = NULL
) +
theme_ipsum(grid="") +
theme(legend.position = "none")
}) |>
do.call(what = "wrap_plots") +
plot_annotation(
title="Flexoki Continuous Color Scales",
subtitle="All 8 continuous color palettes",
caption="Using scale_fill_flexoki_continuous()",
theme = theme_ipsum(grid="")
)
```

<img src="man/figures/README-flexoki3-1.png" width="960" />
Expand All @@ -371,10 +375,10 @@ p %+% data.frame(

| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
|:-----|---------:|-----:|-----:|-----:|------------:|----:|---------:|----:|
| R | 22 | 0.41 | 1626 | 0.42 | 297 | 0.5 | 1003 | 0.5 |
| R | 22 | 0.41 | 1633 | 0.42 | 297 | 0.5 | 1003 | 0.5 |
| SVG | 4 | 0.07 | 310 | 0.08 | 0 | 0.0 | 0 | 0.0 |
| JSON | 1 | 0.02 | 15 | 0.00 | 0 | 0.0 | 0 | 0.0 |
| SUM | 27 | 0.50 | 1951 | 0.50 | 297 | 0.5 | 1003 | 0.5 |
| SUM | 27 | 0.50 | 1958 | 0.50 | 297 | 0.5 | 1003 | 0.5 |

{cloc} 📦 metrics for hrbrthemes

Expand Down
48 changes: 27 additions & 21 deletions README.qmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
format: gfm
editor_options:
chunk_output_type: console
---
```{r pkg-knitr-opts, include=FALSE}
hrbrpkghelpr::global_opts()
Expand Down Expand Up @@ -277,29 +279,33 @@ ggplot(mpg, aes(displ, hwy, color=class)) +
scale_color_flexoki_dark()
```

```{r flexoki3, fig.width=10, fig.height=6}
# Continuous color scales
library(tidyr)
expand.grid(x=1:50, y=1:50) %>%
mutate(z = sqrt((x-25)^2 + (y-25)^2)) %>%
ggplot(aes(x, y, fill=z)) +
geom_tile() +
facet_wrap(~palette, ncol=4) +
scale_fill_flexoki_continuous() +
labs(title="Flexoki Continuous Color Scales",
subtitle="All 8 continuous color palettes",
caption="Using scale_fill_flexoki_continuous()") +
theme_ipsum(grid="") +
theme(legend.position="none") -> p
p %+% data.frame(
```{r flexoki3, fig.width=10, fig.height=11}
library(patchwork)
data.frame(
x = rep(1:50, 50),
y = rep(1:50, each=50),
z = sqrt((rep(1:50, 50)-25)^2 + (rep(1:50, each=50)-25)^2),
palette = factor(rep(c("red", "orange", "yellow", "green",
"cyan", "blue", "purple", "magenta"), each=2500))
)
z = sqrt((rep(1:50, 50)-25)^2 + (rep(1:50, each=50)-25)^2)
) -> grad_df
names(flexoki_dark) |>
map(\(.p) {
ggplot(grad_df, aes(x, y, fill=z)) +
geom_tile() +
scale_fill_flexoki_continuous(palette = .p) +
labs(
x = NULL, y = NULL
) +
theme_ipsum(grid="") +
theme(legend.position = "none")
}) |>
do.call(what = "wrap_plots") +
plot_annotation(
title="Flexoki Continuous Color Scales",
subtitle="All 8 continuous color palettes",
caption="Using scale_fill_flexoki_continuous()",
theme = theme_ipsum(grid="")
)
```

### hrbrthemes Metrics
Expand Down
Binary file modified man/figures/README-flexoki3-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-ps-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 2469415

Please sign in to comment.