davidhodge931 / ggblanket

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

scales 2.0 #919

Closed davidhodge931 closed 1 month ago

davidhodge931 commented 1 month ago

If *_symmetric = TRUE, then:

If *_symmetric = FALSE, then:

Remove

Instead, users can get what they want using a combo of:

Make expand limits work the same way as ggplot2

x, y, col

davidhodge931 commented 1 month ago
library(tidyverse)
library(palmerpenguins)
library(ggblanket)
############################
#if stat is identity...
############################
penguins |>
  filter(between(bill_depth_mm, 0, 15)) |>
  gg_point(
    x =  bill_depth_mm, 
    y = body_mass_g,
    x_expand_limits = 13,
    x_expand = c(0, 0),
  ) 

############################
#otherwise if stat is not identity...
############################

#To zoom in, use coord and *_breaks 
penguins |>
  gg_smooth(
    x =  body_mass_g, 
    y = bill_depth_mm,
    se = TRUE,
    coord = coord_cartesian(ylim = c(NA, 15)), 
    y_breaks = scales::breaks_width(0.05), #need to recreate breaks on symmetric axis
    # y_symmetric = FALSE,
  ) 

#To zoom out, use *_expand_limits
penguins |>
  gg_smooth(
    x =  body_mass_g, 
    y = bill_depth_mm,
    se = TRUE,
    x_expand_limits = c(0),
    # y_expand_limits = c(10, 25),
  ) 
davidhodge931 commented 1 month ago

Make an edge case work

library(tidyverse)
library(palmerpenguins)
library(ggblanket)

set_blanket()

diamonds |>
  gg_bin_2d(
    x = carat,
    y = price,
    y_symmetric = FALSE, #make the limits the min/max
    y_expand_limits = 20000,
    y_expand = c(0, 0),
  )

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