Skip to content

Commit

Permalink
upkeeeep
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Oct 25, 2024
1 parent fda519e commit 9008adc
Show file tree
Hide file tree
Showing 39 changed files with 1,597 additions and 119 deletions.
27 changes: 14 additions & 13 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ on:
pull_request:
branches: [main, master]

name: R-CMD-check
name: R-CMD-check.yaml

permissions: read-all

jobs:
R-CMD-check:
Expand All @@ -25,24 +27,22 @@ jobs:
- {os: macos-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}
# use 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: '4.1'}

- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'oldrel-3'}
- {os: ubuntu-latest, r: 'oldrel-4'}
# use 4.0 or 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: 'oldrel-4'}

- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'oldrel-3'}
- {os: ubuntu-latest, r: 'oldrel-4'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -60,3 +60,4 @@ jobs:
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
8 changes: 5 additions & 3 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ on:
types: [published]
workflow_dispatch:

name: pkgdown
name: pkgdown.yaml

permissions: read-all

jobs:
pkgdown:
Expand All @@ -22,7 +24,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -41,7 +43,7 @@ jobs:

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/pr-commands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ on:
issue_comment:
types: [created]

name: Commands
name: pr-commands.yaml

permissions: read-all

jobs:
document:
Expand All @@ -13,8 +15,10 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/pr-fetch@v2
with:
Expand Down Expand Up @@ -50,8 +54,10 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/pr-fetch@v2
with:
Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ on:
pull_request:
branches: [main, master]

name: test-coverage
name: test-coverage.yaml

permissions: read-all

jobs:
test-coverage:
Expand All @@ -15,36 +17,45 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
covr::codecov(
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: scales
Title: Scale Functions for Visualization
Version: 1.3.0.9000
Authors@R: c(
person("Hadley", "Wickham", , "[email protected]", role = c("aut")),
person("Hadley", "Wickham", , "[email protected]", role = "aut"),
person("Thomas Lin", "Pedersen", , "[email protected]", role = c("cre", "aut"),
comment = c(ORCID = "0000-0002-5147-4711")),
person("Dana", "Seidel", role = "aut"),
Expand All @@ -14,7 +14,7 @@ License: MIT + file LICENSE
URL: https://scales.r-lib.org, https://github.com/r-lib/scales
BugReports: https://github.com/r-lib/scales/issues
Depends:
R (>= 3.6)
R (>= 4.0)
Imports:
cli,
farver (>= 2.0.3),
Expand All @@ -35,6 +35,7 @@ Suggests:
testthat (>= 3.0.0)
Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Config/usethis/last-upkeep: 2024-10-24
Encoding: UTF-8
LazyLoad: yes
Roxygen: list(markdown = TRUE, r6 = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2023
YEAR: 2024
COPYRIGHT HOLDER: scales authors
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2023 scales authors
Copyright (c) 2024 scales authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ S3method(rescale_mid,logical)
S3method(rescale_mid,numeric)
S3method(round_any,POSIXct)
S3method(round_any,numeric)
S3method(toPaletteFunc,"function")
S3method(toPaletteFunc,character)
S3method(toPaletteFunc,matrix)
export(ContinuousRange)
export(DiscreteRange)
export(Range)
Expand Down
3 changes: 3 additions & 0 deletions R/colour-mapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ toPaletteFunc <- function(pal, alpha, nlevels) {

# Strings are interpreted as color names, unless length is 1 and it's the name
# of an RColorBrewer palette that is marked as qualitative
#' @export
toPaletteFunc.character <- function(pal, alpha, nlevels) {
if (length(pal) == 1 && pal %in% row.names(RColorBrewer::brewer.pal.info)) {
paletteInfo <- RColorBrewer::brewer.pal.info[pal, ]
Expand All @@ -338,11 +339,13 @@ toPaletteFunc.character <- function(pal, alpha, nlevels) {
}

# Accept colorRamp style matrix
#' @export
toPaletteFunc.matrix <- function(pal, alpha, nlevels) {
toPaletteFunc(farver::decode_colour(pal), alpha = alpha)
}

# If a function, just assume it's already a function over [0-1]
#' @export
toPaletteFunc.function <- function(pal, alpha, nlevels) {
pal
}
Expand Down
79 changes: 54 additions & 25 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ output: github_document

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, echo = FALSE}
```{r}
#| include: false
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
Expand All @@ -15,18 +16,19 @@ knitr::opts_chunk$set(
```

# scales <a href="https://scales.r-lib.org/"><img src="man/figures/logo.png" align="right" height="138" alt="scales website" /></a>

<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/scales)](https://CRAN.R-project.org/package=scales)
[![R-CMD-check](https://github.com/r-lib/scales/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/scales/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/r-lib/scales/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/scales?branch=main)
[![Codecov test coverage](https://codecov.io/gh/r-lib/scales/graph/badge.svg)](https://app.codecov.io/gh/r-lib/scales)
<!-- badges: end -->

One of the most difficult parts of any graphics package is scaling, converting from data values to perceptual properties. The inverse of scaling, making guides (legends and axes) that can be used to read the graph, is often even harder! The scales packages provides the internal scaling infrastructure used by [ggplot2](https://ggplot2.tidyverse.org/), and gives you tools to override the default breaks, labels, transformations and palettes.

## Installation

```{r, eval = FALSE}
```{r}
#| eval: false
# Scales is installed when you install ggplot2 or the tidyverse.
# But you can install just scales from CRAN:
install.packages("scales")
Expand All @@ -35,45 +37,61 @@ install.packages("scales")
# install.packages("pak")
pak::pak("r-lib/scales")
```

## Usage

### Breaks and labels

The most common use of the scales package is to control the appearance of axis and legend labels. Use a `break_` function to control how breaks are generated from the limits, and a `label_` function to control how breaks are turned in to labels.

```{r labels}
```{r}
#| label: labels
#| fig-alt: >
#| A line plot created with ggplot2, showing property sales in Texas. The x scale
#| uses `scales::break_width()` to place breaks every second year, and
#| `scales::label_date()` to create a custom format for the labels. The y-scale
#| uses `scales::label_number()` to reformat the labels with
#| `scales::cut_short_scale()`.
library(ggplot2)
library(dplyr, warn.conflicts = FALSE)
library(lubridate, warn.conflicts = FALSE)
txhousing %>%
mutate(date = make_date(year, month, 1)) %>%
group_by(city) %>%
filter(min(sales) > 5e2) %>%
ggplot(aes(date, sales, group = city)) +
geom_line(na.rm = TRUE) +
txhousing %>%
mutate(date = make_date(year, month, 1)) %>%
group_by(city) %>%
filter(min(sales) > 5e2) %>%
ggplot(aes(date, sales, group = city)) +
geom_line(na.rm = TRUE) +
scale_x_date(
NULL,
breaks = scales::breaks_width("2 years"),
breaks = scales::breaks_width("2 years"),
labels = scales::label_date("'%y")
) +
) +
scale_y_log10(
"Total sales",
labels = scales::label_number(scale_cut = scales::cut_short_scale())
)
```

economics %>%
filter(date < ymd("1970-01-01")) %>%
ggplot(aes(date, pce)) +
geom_line() +
```{r}
#| fig-alt: >
#| A line plot created with ggplot2, showing personal expenses between 1967 and
#| 1970. The x axis uses `scales::break_width()` to put a break every 3 months
#| and `scales::label_date_short()` to only show the year on the first occuring
#| break of that year. The y axis uses `scales::breaks_extended()` to request
#| 8 breaks, though only 6 are ultimately provided, and
#| `scales::label_dollar()` to format the label as a dollar value.
economics %>%
filter(date < ymd("1970-01-01")) %>%
ggplot(aes(date, pce)) +
geom_line() +
scale_x_date(NULL,
breaks = scales::breaks_width("3 months"),
breaks = scales::breaks_width("3 months"),
labels = scales::label_date_short()
) +
) +
scale_y_continuous("Personal consumption expenditures",
breaks = scales::breaks_extended(8),
labels = scales::label_dollar()
labels = scales::label_dollar()
)
```

Expand All @@ -83,7 +101,13 @@ Generally, I don't recommend running `library(scales)` because when you type (e.

Scales colour palettes are used to power the scales in ggplot2, but you can use them in any plotting system. The following example shows how you might apply them to a base plot.

```{r, palettes}
```{r}
#| label: palettes
#| fig-alt: >
#| A scatterplot created with base plot showing the relationship between
#| sepal length and sepal width in the Iris dataset. The points are coloured
#| according to species and the `scales::pal_brewer()` are used to provide the
#| colours.
library(scales)
# pull a list of colours from any palette
pal_viridis()(4)
Expand All @@ -94,10 +118,15 @@ par(mar = c(5, 5, 1, 1))
plot(Sepal.Length ~ Sepal.Width, data = iris, col = Species, pch = 20)
```

scales also gives users the ability to define and apply their own custom
scales also gives users the ability to define and apply their own custom
transformation functions for repeated use.

```{r transforms}
```{r}
#| label: transforms
#| fig-alt: >
#| A scatterplot created with ggplot2 showing the relationship between diamond
#| price and its carat for a subset of the data in the diamonds dataset. The
#| y scale uses a custom log transform created with `scales::new_transform()`.
# use new_transform to build a new transformation
transform_logp3 <- new_transform(
name = "logp",
Expand All @@ -108,6 +137,6 @@ transform_logp3 <- new_transform(
dsamp <- sample_n(diamonds, 100)
ggplot(dsamp, aes(carat, price, colour = color)) +
geom_point() +
geom_point() +
scale_y_continuous(trans = transform_logp3)
```
Loading

0 comments on commit 9008adc

Please sign in to comment.