davidhodge931 / ggblanket

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

should a title or label attribute be supported? #840

Closed davidhodge931 closed 6 months ago

davidhodge931 commented 6 months ago
devtools::load_all()
#> ℹ Loading ggplot2

df <- mtcars
attr(df$mpg,  "label") <- "Miles per gallon"
attr(df$disp, "label") <- "Displacement"
attr(df$drat, "label") <- "Rear axle ratio"

attr(df[["drat"]], "label")
attr(df[["cyl"]], "label")

p <- ggplot(df, aes(mpg, .data$disp)) +
  geom_point(aes(colour = drat)) +
  labs()

p
davidhodge931 commented 6 months ago

Only will work for x, y and col

davidhodge931 commented 6 months ago
library(tidyverse)
library(ggblanket)

set_blanket()

df <- mtcars |> 
  mutate(cyl = factor(cyl))  

attr(df$mpg,  "label") <- "Miles per gallon"
attr(df$disp, "label") <- "Displacement"
attr(df$drat, "label") <- "Rear axle ratio"
attr(df$cyl, "label") <- "Cylinder"
attr(df$wt, "label") <- "Weight"
attr(df$hp, "label") <- "Horsepower"

df |>
  gg_point(
    x = wt,
    y = hp,
    col = cyl,
  ) 


df |>
  gg_histogram(
    x = wt,
    col = cyl,
  )
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Created on 2024-05-04 with reprex v2.1.0