plot_deciles: Plot decile plots of numerical variables

Description Usage Arguments Examples

View source: R/plot_deciles.R

Description

This function creates nicely formatted, standardised decile plots. Prior to calling the function the data should only be in a form of a decile table calculate_decile_table. Above each bar the median value of the bin is displayed.

Usage

1
2
3
4
5
plot_deciles(df, x = decile, y = ratio, facet = NULL, ticks = 10,
  angle = 0, title = TRUE, subtitle = NULL, caption = NULL,
  lab_x = "Decile", lab_y = "Ratio", legend = TRUE, alpha = 0.7,
  quantile_low = 0, quantile_high = 1, theme_type = "ipsum",
  palette = "awtools")

Arguments

df

A data frame.

x

A categorical variable for the x axis groupings. Defaults to 'decile'.

y

A numerical variable for the y axis levels. Defaults to 'ratio'.

facet

Select an additional faceting variable to create facets. Defaults to NULL.

ticks

Select the number of ticks on the x and y axis with the number_ticks function. Defaults to 10.

angle

Select the rotation angle for the x axis labels. Defaults to 0.

title

Should the plot title appear automatically. Defaults to TRUE.

subtitle

Text that is displayed on the subtitle. Defaults to NULL.

caption

Text that is displayed on the caption. Defaults to NULL.

lab_x

Text that is displayed on the x axis. Defaults to "Decile".

lab_y

Text that is displayed on the y axis. Defaults to "Percentage".

legend

Should the plot legend appear automatically. Defaults to TRUE.

alpha

Select plot fill transparency. Defaults to 0.7.

quantile_low

Select lower percentile for outliers exclusion. Defaults to 0.0%.

quantile_high

Select upper percentile for outliers exclusion. Defaults to 1.0%.

theme_type

Select a theme type from themes available in the apply_theme function. Defaults to "ipsum".

palette

Select a palette type with the select_palette function. Defaults to "awtools".

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(tidyverse)

diamonds_filter <- diamonds %>% filter(cut %in% c("Ideal", "Premium"))

diamonds_filter %>%
  calculate_decile_table(price, cut, "Ideal") %>%
  plot_deciles()

diamonds_filter %>%
  calculate_decile_table(binning = price,
                         grouping = cut,
                         top_level = "Ideal",
                         n_bins = 10,
                         format = FALSE,
                         color) %>%
  plot_deciles(facet = color)

konradsemsch/ggrapid documentation built on Nov. 4, 2019, 3:56 p.m.