scales

Tools for ggplot2 scales

https://github.com/r-lib/scales

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    5 of 57 committers (8.8%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (17.3%) to scientific vocabulary

Keywords

ggplot2 r

Keywords from Contributors

visualisation tidy-data package-creation grammar data-manipulation pandoc rmarkdown date-time documentation-tool curl
Last synced: 6 months ago · JSON representation

Repository

Tools for ggplot2 scales

Basic Info
  • Host: GitHub
  • Owner: r-lib
  • License: other
  • Language: R
  • Default Branch: main
  • Homepage: https://scales.r-lib.org
  • Size: 34.6 MB
Statistics
  • Stars: 437
  • Watchers: 17
  • Forks: 115
  • Open Issues: 27
  • Releases: 13
Topics
ggplot2 r
Created over 15 years ago · Last pushed 10 months ago
Metadata Files
Readme Changelog License Code of conduct Codeowners

README.Rmd

---
output: github_document
---



```{r}
#| include: false
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  fig.width = 5,
  fig.height = 3
)
```

# scales scales website


[![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/graph/badge.svg)](https://app.codecov.io/gh/r-lib/scales)


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
# Scales is installed when you install ggplot2 or the tidyverse.
# But you can install just scales from CRAN:
install.packages("scales")

# Or the development version from Github:
# 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}
#| 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) +
  scale_x_date(
    NULL,
    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())
  )
```

```{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"),
    labels = scales::label_date_short()
  ) +
  scale_y_continuous("Personal consumption expenditures",
    breaks = scales::breaks_extended(8),
    labels = scales::label_dollar()
  )
```

Generally, I don't recommend running `library(scales)` because when you type (e.g.) `scales::label_` autocomplete will provide you with a list of labelling functions to jog your memory.

### Advanced features

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}
#| 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)

# use in combination with baseR `palette()` to set new defaults
palette(pal_brewer(palette = "Set2")(4))
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
transformation functions for repeated use.

```{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",
  transform = function(x) log(x + 3),
  inverse = function(x) exp(x) - 3,
  breaks = log_breaks()
)

set.seed(1234) # Ensures same sampling
dsamp <- sample_n(diamonds, 100)
ggplot(dsamp, aes(carat, price, colour = color)) +
  geom_point() +
  scale_y_continuous(trans = transform_logp3)
```

Owner

  • Name: R infrastructure
  • Login: r-lib
  • Kind: organization

GitHub Events

Total
  • Create event: 3
  • Release event: 1
  • Issues event: 57
  • Watch event: 33
  • Delete event: 1
  • Issue comment event: 46
  • Push event: 71
  • Pull request event: 39
  • Pull request review event: 29
  • Pull request review comment event: 10
  • Fork event: 6
Last Year
  • Create event: 3
  • Release event: 1
  • Issues event: 57
  • Watch event: 33
  • Delete event: 1
  • Issue comment event: 46
  • Push event: 71
  • Pull request event: 39
  • Pull request review event: 29
  • Pull request review comment event: 10
  • Fork event: 6

Committers

Last synced: 8 months ago

All Time
  • Total Commits: 701
  • Total Committers: 57
  • Avg Commits per committer: 12.298
  • Development Distribution Score (DDS): 0.427
Past Year
  • Commits: 45
  • Committers: 9
  • Avg Commits per committer: 5.0
  • Development Distribution Score (DDS): 0.444
Top Committers
Name Email Commits
hadley h****m@g****m 402
Thomas Lin Pedersen t****5@g****m 66
Teun van den Brand 4****d 34
Dana Seidel d****l@b****u 30
Winston Chang w****n@s****g 25
Dana Paige Seidel d****a@r****m 17
Kara Woo k****o 13
Brian Diggs d****b@o****u 9
Joe Cheng j****e@r****g 9
dougmitarotonda d****a@g****m 8
Claus Wilke w****e@a****u 6
Sergio Oller s****r@g****m 6
Joseph j****e@g****m 6
Jean-Olivier Irisson i****n@n****g 5
aaronwolen a****n@w****m 4
Mara Averick m****k@g****m 4
Jim Hester j****r@g****m 4
David C Hall d****l 3
Hiroaki Yutani y****i@g****m 3
jrnold j****d@g****m 3
ThierryO g****2@m****e 3
dvmlls d****s 2
Robert Zamora z****r@g****m 2
Mikko Marttila m****t@m****m 2
Matthew Kay m****y@g****m 2
Bill Denney b****y 2
David Mills d****s@t****m 1
Alex Hamilton 1****o 1
seaaan s****n@g****m 1
ewen e****n@g****m 1
and 27 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 125
  • Total pull requests: 64
  • Average time to close issues: 9 months
  • Average time to close pull requests: 4 months
  • Total issue authors: 64
  • Total pull request authors: 20
  • Average comments per issue: 1.52
  • Average comments per pull request: 1.58
  • Merged pull requests: 47
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 31
  • Pull requests: 33
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 22 days
  • Issue authors: 18
  • Pull request authors: 7
  • Average comments per issue: 0.55
  • Average comments per pull request: 0.7
  • Merged pull requests: 27
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • davidhodge931 (21)
  • teunbrand (19)
  • thomasp85 (11)
  • hadley (7)
  • lz1nwm (2)
  • DavisVaughan (2)
  • dmurdoch (2)
  • mjskay (2)
  • yutannihilation (2)
  • ccsarapas (2)
  • paleolimbot (2)
  • Moohan (1)
  • rogiersbart (1)
  • kuriwaki (1)
  • smu (1)
Pull Request Authors
  • teunbrand (54)
  • thomasp85 (4)
  • zeehio (3)
  • pearsonca (3)
  • EricMarcon (3)
  • Moohan (2)
  • d-morrison (2)
  • kellijohnson-NOAA (2)
  • Aehmlo (2)
  • hadley (2)
  • ndevln (2)
  • mjskay (2)
  • MichaelChirico (2)
  • johanneskoch94 (1)
  • ari-nz (1)
Top Labels
Issue Labels
feature (12) help wanted :heart: (3) bug (2) documentation (2) upkeep (2) tidy-dev-day :nerd_face: (1)
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • cran 1,286,182 last-month
  • Total docker downloads: 201,329,351
  • Total dependent packages: 1,062
    (may contain duplicates)
  • Total dependent repositories: 4,475
    (may contain duplicates)
  • Total versions: 31
  • Total maintainers: 1
cran.r-project.org: scales

Scale Functions for Visualization

  • Versions: 18
  • Dependent Packages: 1,062
  • Dependent Repositories: 4,475
  • Downloads: 1,286,182 Last month
  • Docker Downloads: 201,329,351
Rankings
Dependent packages count: 0.1%
Dependent repos count: 0.1%
Downloads: 0.1%
Forks count: 0.6%
Stargazers count: 1.0%
Average: 3.2%
Docker downloads count: 17.3%
Maintainers (1)
Last synced: 6 months ago
proxy.golang.org: github.com/r-lib/scales
  • Versions: 13
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.5%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.2 depends
  • R6 * imports
  • RColorBrewer * imports
  • farver >= 2.0.3 imports
  • labeling * imports
  • lifecycle * imports
  • munsell >= 0.5 imports
  • rlang >= 1.0.0 imports
  • viridisLite * imports
  • bit64 * suggests
  • covr * suggests
  • dichromat * suggests
  • ggplot2 * suggests
  • hms >= 0.5.0 suggests
  • stringi * suggests
  • testthat >= 3.0.0 suggests
  • waldo >= 0.4.0 suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action 4.1.4 composite
  • actions/checkout v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pr-commands.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/pr-fetch v2 composite
  • r-lib/actions/pr-push v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite