Giter Site home page Giter Site logo

davidhodge931 / ggblanket Goto Github PK

View Code? Open in Web Editor NEW
135.0 4.0 8.0 689.71 MB

Simplify ggplot2 visualisation

Home Page: https://davidhodge931.github.io/ggblanket/

License: Other

R 100.00%
data-visualisation data-visualization ggplot ggplot-extension ggplot2 ggplot2-enhancements r r-package visualisation visualization

ggblanket's Introduction

ggblanket

CRAN status CRAN RStudio mirror downloads CRAN RStudio mirror downloads CRAN RStudio mirror downloads CRAN RStudio mirror downloads R-CMD-check

Overview

ggblanket is a package of ggplot2 wrapper functions.

The primary objective is to simplify ggplot2 visualisation.

Secondary objectives relate to:

  • Design: produce well-designed visualisation
  • Alignment: use conventions aligned with ggplot2
  • Scope: cover much of what ggplot2 does.

Computational speed has been traded-off to achieve these objectives.

Installation

install.packages("ggblanket")

Example

library(ggblanket)
library(palmerpenguins)

set_blanket()

penguins |>
  gg_histogram(
    x = flipper_length_mm,
    col = species,
  )

Get started

Click here to start learning how ggblanket works.

Thank you

Thanks to all authors of ggplot2, tidyverse, and the wider R ecosystem.

This R package is dedicated to my Dad (Peter Hodge, 1953โ€“2023).

ggblanket's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ggblanket's Issues

x_zero & y_zero defaults for blank

Where there is continuous colour, zero-ing looks bad

image

Question:

  • to make people convert limits to data min/max where it looks bad
  • to change it in particular geoms where it makes sense to??

hms class does not work (i.e. time)

No scale present for time

lakers %>%
  slice_sample(n = 100) %>% 
  tibble() %>% select(time, points) %>% 
  mutate(time = lubridate::hm(time)) %>% 
  gg_blank(time, points) +
  geom_point() +
  scale_x_time()

x/y_balance

Ideally it would be:

x_breaks_mid = 0
y_breaks_mid = 0

x/y_zero

Ideally it would be:

x_limits_include = c(0)
y_limits_include = c(0)

col_method revise, Maybe call it `col_chop`

3 options:

1). Specify an argument, which does it for people.

evenly ...intervals (i.e. col_chop_n = blah) #by width
quantiles ...probs (i.e. col_chop_probs = blah) #by number of elements
mean_sd ..sds (i.e. col_probs_sds = blah) #by statistics
exactly ...breaks (i.e. col_breaks = blah).
pretty

Pro's:

  • can make labels default to nice stuff, and link fmt to col_labels
  • people can make their own var in the data if it's not working for them

Con's lots of args

  1. People add a chop function

penguins %>%
gg_blank(bill_length_mm, flipper_length_mm, body_mass_g, x_zero = F, y_zero = F,
col_labels = ~ prettyNum(.x, big.mark = "", scientific = FALSE),
pal = pal_viridis_reorder(5),
col_chop = ~ santoku::chop_evenly(.x, intervals = 5)
) +
geom_point()


3. Make people do it themselves

x & y scales bugs out when x_breaks or y_breaks specified

library(ggplot2)
library(palmerpenguins)

ggplot(penguins) +
  geom_point(aes(x = body_mass_g, y = flipper_length_mm)) +
  scale_x_continuous(breaks = scales::breaks_width(550))

x_breaks <- scales::fullseq(range(penguins$body_mass_g, na.rm = T), size = 550)

gg_point(penguins, body_mass_g, flipper_length_mm,
         x_breaks = c( 2200, 2750, 3300, 3850, 4400, 4950, 5500, 6050, 6600))

gg_point(penguins, body_mass_g, flipper_length_mm,
         y_breaks = c(160, 190, 240))

x_breaks <- scales::fullseq(range(economics$date, na.rm = T), size = "2 years")

Package names

library(ggrescale)

What is the package doing?
1). quick aes: uses quick syntax for aesthetics
2). facet as if an aes: simplifies facetting by treating facet as if it is an aesthetic
3). combines col/fill aes simplifies colour via pal argument, and combining col/fill
4). rescales x/y limits: creates adjustable x and y scales, where limits = min/max breaks
5). reordering: updates order of horizontal geom y and col, including legends, so everything is in order
6). default format: convert labels and titles to sentence case and comma

library(ggremix)

histogram methods for scale don't work

This occurs because the graph is built using ggplot2 default x/y scales

In histogram, the limits affect the data because in histogram the area between the x_limits affects the size of the y values computed.

image

For all geom's, the build of the ggplot is used to compute the x and y numeric scales. This is because the different positions and stats result in different x and y values.

For gg_histogram, you might have to do something different...

If x is not null, calculate the x_breaks and x_scale based on x_var_vctr, and feed into the ggplot2 build

If y is not null, calculate the y_breaks and y_scale based on the y_var_vctr and feed into the ggplot2

Maybe this should be done in blank??

Use dots to access other args in geom_

library(tidyverse)
library(palmerpenguins)

smoother <- function(data, x, y, method = "lm", ...) {
    ggplot(data) +
    geom_smooth(aes({{x}}, {{y}}), method = method, ...)
}

smoother(penguins, flipper_length_mm, body_mass_g)
smoother(penguins, flipper_length_mm, body_mass_g, method = "loess")

col discrete scale

library(tidyverse)

breaks <- c("Chinstrap", "Adelie", "Gentoo", "Another one")
values <- c("green", "blue", "red", "pink")
pal_df <- tibble::tibble(breaks, values)

ggplot(penguins) +
geom_point(aes(flipper_length_mm, body_mass_g, col = species)) +
scale_color_manual(values = pal_df$values, breaks = pal_df$breaks, drop = FALSE)

Something cool

library(palmerpenguins)
library(tidyverse)

plot_data <- storms %>%
group_by(year, status) %>%
summarise(wind = mean(wind, na.rm = T))

plot_data %>%
ggplot(aes(year, wind, col = status)) +
geom_line() +
geom_line(aes(col = "All of NZ"),
data = plot_data %>% group_by(year) %>% summarise(wind = sum(wind)))

how to make a column chart with gg_blank

gg_blank(penguins, 
         x = body_mass_g, 
         y = flipper_length_mm, 
         dye = sex,
         y_zero = TRUE, 
         position = "fill", 
         x_limits = c(NA, NA),
         ) +
  geom_col(aes(x = body_mass_g, 
               y = flipper_length_mm, 
               col = sex, fill = sex), 
           position = "fill")

colour method sorted :)

Default to continuous

Default to col_bins = NULL, which can colour continuously

Choose col_bins = "evenly" to turn chopping on
"evenly", "quantiles", "mean_sd"

Fine-tune with arg's:
col_intervals = 5
col_probs = seq(0, 1, 0.25)
col_sds = 1:3
col_pretty_n = 5
col_breaks = c(0, 300, 500, 1000)

Might need some work with col_breaks to make it work with gradient

Make it all left, and colour them using nice existing method

package name: ggblanket or blanket

library(blanket)
-pros: more readable
-cons: not linked to ggplot, unless you know about it, not a name for a leaf wrapper package available

library(ggblanket)

date_time *_breaks do not work

image

library(tidyverse)
library(lubridate)
library(ggblanket)

df <- lakers %>%
  slice_sample(n = 100) %>% 
  tibble() 

df %>% 
  gg_blank(time, points, x_breaks_n = 5) +
  geom_point()

x_zero is not working all the time

gg_blank(storms, x = year, y = wind, stat = "boxplot", position = "dodge2", x_zero = F) +
  geom_boxplot(aes(group = year), stat = "boxplot", position = "dodge2", alpha = 0.5)

image

Add breaks_width argument

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

df <- penguins %>% 
  drop_na(body_mass_g)

breaks_n
breaks_width

scales::fullseq(range(df$body_mass_g), size = 750)
scales::fullseq(range(economics$date), size = "1 year")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.