README.md

ggois

The goal of ggois is to make plots for in O&S style.

Installation

You can install ggois from github with:

# install.packages("devtools")
devtools::install_github("brilstl/ggois")

Example

This is a basic example of a plot with the theme_ois() function:

library(ggois)
library(tidyverse)
#> -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
#> v ggplot2 3.3.5     v purrr   0.3.4
#> v tibble  3.1.6     v dplyr   1.0.8
#> v tidyr   1.2.0     v stringr 1.4.0
#> v readr   2.0.0     v forcats 0.5.1
#> Warning: package 'tibble' was built under R version 4.1.2
#> Warning: package 'tidyr' was built under R version 4.1.3
#> Warning: package 'dplyr' was built under R version 4.1.3
#> -- Conflicts ------------------------------------------ tidyverse_conflicts() --
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag()    masks stats::lag()

# plot ----

diamonds %>% 
  ggplot(
  aes(x = price,
      y = cut)) +
  geom_boxplot(colour = os_colours$red) +
  theme_ois()

ggois also has some convenient functions for making tables and plots. The package is designed in a (generalized) linear algebra fashion (y ~ x). This means that every functions includes the paramters data, y and x. Some functions also allow for a moderator (y ~ x*z). The packages has functions such as ggois_bar_chart and ggois_likert_chart, which create a summary tibble. The summary tibble inherits a class, by which the functions autoplot and autotable know how to interpret the data for plotting and creating tables. See examples below:

bar plot

example_bar <- diamonds %>% 
  ggois_bar_chart(cut, price)


example_bar
#> # A tibble: 5 x 3
#> # Groups:   .y [5]
#>   .y         .waarde percent
#>   <ord>        <int>   <dbl>
#> 1 Fair       7017600  0.0331
#> 2 Good      19275009  0.0909
#> 3 Very Good 48107623  0.227 
#> 4 Premium   63221498  0.298 
#> 5 Ideal     74513487  0.351

plot

example_bar %>% 
  autoplot()

table

example_bar %>% 
  autotable() %>% 
  gt::as_raw_html()
.y .waarde percent Ideal 74513487 35% Premium 63221498 30% Very Good 48107623 23% Good 19275009 9% Fair 7017600 3%

likert plot

example_likert <- diamonds %>% 
  ggois_likert_chart(cut, clarity)


example_likert
#> # A tibble: 40 x 4
#> # Groups:   .y [5]
#>    .y    .x    .waarde percent
#>    <ord> <ord>   <int>   <dbl>
#>  1 Fair  I1        210 0.130  
#>  2 Fair  SI2       466 0.289  
#>  3 Fair  SI1       408 0.253  
#>  4 Fair  VS2       261 0.162  
#>  5 Fair  VS1       170 0.106  
#>  6 Fair  VVS2       69 0.0429 
#>  7 Fair  VVS1       17 0.0106 
#>  8 Fair  IF          9 0.00559
#>  9 Good  I1         96 0.0196 
#> 10 Good  SI2      1081 0.220  
#> # ... with 30 more rows

plot

example_likert %>% 
  autoplot()

table

example_likert %>% 
  autotable() %>% 
  gt::as_raw_html()
cut I1 IF SI1 SI2 VS1 VS2 VVS1 VVS2 % n % n % n % n % n % n % n % n Fair 13% 210 1% 9 25% 408 29% 466 11% 170 16% 261 1% 17 4% 69 Good 2% 96 1% 71 32% 1560 22% 1081 13% 648 20% 978 4% 186 6% 286 Very Good 1% 84 2% 268 27% 3240 17% 2100 15% 1775 21% 2591 7% 789 10% 1235 Premium 1% 205 2% 230 26% 3575 21% 2949 14% 1989 24% 3357 4% 616 6% 870 Ideal 1% 146 6% 1212 20% 4282 12% 2598 17% 3589 24% 5071 9% 2047 12% 2606

likert plot with moderator

example_likert <- diamonds %>% 
  filter(color %in% c("D", "E", "F")) %>% 
  ggois_likert_chart(cut, clarity, color)


example_likert
#> # A tibble: 119 x 5
#> # Groups:   .y, .z [15]
#>    .y    .z    .x    .waarde percent
#>    <ord> <ord> <ord>   <int>   <dbl>
#>  1 Fair  D     I1          4  0.0245
#>  2 Fair  D     SI2        56  0.344 
#>  3 Fair  D     SI1        58  0.356 
#>  4 Fair  D     VS2        25  0.153 
#>  5 Fair  D     VS1         5  0.0307
#>  6 Fair  D     VVS2        9  0.0552
#>  7 Fair  D     VVS1        3  0.0184
#>  8 Fair  D     IF          3  0.0184
#>  9 Fair  E     I1          9  0.0402
#> 10 Fair  E     SI2        78  0.348 
#> # ... with 109 more rows

plot

example_likert %>% 
  autoplot()

table

example_likert %>% 
  autotable() %>% 
  gt::as_raw_html()
cut I1 IF SI1 SI2 VS1 VS2 VVS1 VVS2 % n % n % n % n % n % n % n % n D Fair 2% 4 2% 3 36% 58 34% 56 3% 5 15% 25 2% 3 6% 9 Good 1% 8 1% 9 36% 237 34% 223 6% 43 16% 104 2% 13 4% 25 Very Good 0% 5 2% 23 33% 494 21% 314 12% 175 20% 309 3% 52 9% 141 Premium 1% 12 1% 10 35% 556 26% 421 8% 131 21% 339 2% 40 6% 94 Ideal 0% 13 1% 28 26% 738 13% 356 12% 351 32% 920 5% 144 10% 284 E Fair 4% 9 0% 0 29% 65 35% 78 6% 14 19% 42 1% 3 6% 13 Good 2% 23 1% 9 38% 355 22% 202 10% 89 17% 160 5% 43 6% 52 Very Good 1% 22 2% 43 26% 626 19% 445 12% 293 21% 503 7% 170 12% 298 Premium 1% 30 1% 27 26% 614 22% 519 12% 292 27% 629 4% 105 5% 121 Ideal 0% 18 2% 79 20% 766 12% 469 15% 593 29% 1136 9% 335 13% 507 F Fair 11% 35 1% 4 27% 83 29% 89 11% 33 17% 53 2% 5 3% 10 Good 2% 19 2% 15 30% 273 22% 201 15% 132 20% 184 4% 35 6% 50 Very Good 1% 13 3% 67 26% 559 16% 343 14% 293 22% 466 8% 174 12% 249 Premium 1% 34 1% 31 26% 608 22% 523 12% 290 27% 619 3% 80 6% 146 Ideal 1% 42 7% 268 16% 608 12% 453 16% 616 23% 879 12% 440 14% 520

changing colors

example_likert %>% 
  autoplot(palette = c(os_colours$pink, "white", os_colours$red))



brilstl/ggois documentation built on May 4, 2022, 5:44 p.m.