davidhodge931 / ggblanket

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

transform #923

Closed davidhodge931 closed 1 month ago

davidhodge931 commented 1 month ago
library(tidyverse)
library(ggblanket)

#date
economics |>
  ggplot(aes(date, unemploy)) +
  geom_line(aes(colour = date)) +
  scale_colour_gradientn(
    colours = viridis::inferno(n = 9),
    transform = scales::transform_date(),
  )

#datetime (i.e."POSIXt" class)
data.frame(
  x = Sys.time() + seq(0, 2e6, length.out = 20),
  y = rnorm(20)
  ) |>
  ggplot(aes(x, y)) +
  geom_line(aes(colour = x)) +
  scale_colour_gradientn(colours = viridis::inferno(n = 9), 
                         transform = scales::transform_time())

#hms
data.frame(
  x = Sys.time() + seq(0, 2e6, length.out = 20),
  y = rnorm(20)
  ) |>
  mutate(x = hms::as_hms(x)) |>
  ggplot(aes(x, y)) +
  geom_line(aes(colour = x)) +
  scale_colour_gradientn(colours = viridis::inferno(n = 9), 
                         transform = scales::transform_hms())
davidhodge931 commented 1 month ago

Sorted :)