Comments (3)
library(tidyverse)
library(palmerpenguins)
hold_3rd <- function(x) {
c("", "", as.character(x[2]), rep("", times = length(x) - 3))
}
penguins |>
ggplot() +
geom_point(
aes(x = bill_length_mm,
y = body_mass_g),
) +
scale_x_continuous(labels = \(x) hold_3rd(scales::comma(x)))
penguins |>
ggplot() +
geom_point(
aes(x = flipper_length_mm,
y = body_mass_g),
) +
scale_x_continuous(labels = \(x) hold_3rd(scales::comma(x)))
from ggblanket.
#' Hold every nth element
#'
#' @description
#' Hold every nth element in a vector, and replace the rest with "".
#'
#' @param x A vector.
#' @param nth The increment of elements to hold as is. Defaults to `2`.
#' @param offset An offset for which element to first hold. Defaults to `0`. Possible values are `-1` to (`nth - 2`)
#'
#' @return A character vector
#' @noRd
#'
#' @examples
#' hold_nth(scales::comma(seq(1000, 5000, 1000)))
#' hold_nth(format(lubridate::ymd(c("2021-01-01", "2022-01-01", "2023-01-01", "2024-01-01"))))
#' hold_nth(LETTERS[1:12])
hold_nth <- function(x,
nth = 2,
offset = 0) {
replace(x, seq_along(x) %% nth != (offset + 1), "")
}
from ggblanket.
Note that ggplot2 applies labelling function prior to breaks, so the first break is often in a confusing and inconsistent place.
Leave this for now until/unless ggplot2 fixes
from ggblanket.
Related Issues (20)
- Colour: make hex codes caps
- code makes the base plot twice uneccesarily!
- set_blanket: add variants HOT 2
- design: force all optional args to be named HOT 2
- docs: use `position_dodge2(preserve = "single")` HOT 1
- aes_contrast: remove mode_family argument
- ness helpers are not well named HOT 2
- Bug: in colouring with when `col_palette_d` was set with names not in the data HOT 1
- set_blanket: non-named values in col scales does not work where there are named values in set col_palette_d HOT 1
- docs: update vignette multiple layers example HOT 1
- rug breaks with DEV ggplot2
- stat bin changes with DEV ggplot2
- *_limits: consider removing from x/y HOT 3
- *_breaks` & `y_limits`: where both set, breaks does not work
- x-scale not working great in the below example HOT 1
- consider shifting default back to grey (and facet shift as well) HOT 1
- positional scales: remove `*_limits`, `*_oob` and `*_expand` HOT 1
- positional scales: make symmetric scale even if *_expand is not NULL
- positional scales: remove `*_transform`
- positional scales: could make symmetric if limits specified by dividing into equal parts
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ggblanket.