davidhodge931 / ggblanket

Simplify ggplot2 visualisation
https://davidhodge931.github.io/ggblanket/
Other
155 stars 8 forks source link

symmetric axis where limits specified (and breaks not specified) #910

Closed davidhodge931 closed 3 months ago

davidhodge931 commented 3 months ago

Should do this....

library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(palmerpenguins)
library(ggblanket)

set_blanket()

x1 <- 2000
x2 <- 9000
n <- 6

penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g,
    col = sex,
    y_limits = range(seq(from = x1, to = x2, by = (x2 - x1) / (n - 1))),
    y_breaks = seq(from = x1, to = x2, by = (x2 - x1) / (n - 1)),
    y_expand = c(0, 0),
  )
#> y 'symmetric' scale cannot be constructed unless `y_limits = NULL` & `y_expand
#> = NULL`
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`).

Created on 2024-06-18 with reprex v2.1.0