Method: Charty::PlotMethods#bar_plot

Defined in:
lib/charty/plot_methods.rb

#bar_plot(x: nil, y: nil, color: nil, data: nil, order: nil, color_order: nil, estimator: :mean, ci: 95, n_boot: 1000, units: nil, random: nil, orient: nil, key_color: nil, palette: nil, saturation:, error_color: [0.26, 0.26, 0.26], error_width: nil, cap_size: nil, dodge: true, log: false, x_label: nil, y_label: nil, title: nil, **options, &block) ⇒ Object

Show the given data as rectangular bars.

Parameters:

  • x (defaults to: nil)

    x-dimension input for plotting long-form data.

  • y (defaults to: nil)

    y-dimension input for plotting long-form data.

  • color (defaults to: nil)

    color-dimension input for plotting long-form data.

  • data (defaults to: nil)

    Dataset for plotting.

  • order (defaults to: nil)

    Order of the categorical dimension to plot the categorical levels in.

  • color_order (defaults to: nil)

    Order of the color dimension to plot the categorical levels in.

  • estimator (defaults to: :mean)

    Statistical function to estimate withint each categorical bin.

  • ci (defaults to: 95)

    Size of confidence intervals to draw around estimated values.

  • n_boot (defaults to: 1000)

    The size of bootstrap sample to use when computing confidence intervals.

  • units (defaults to: nil)

    Identifier of sampling unit.

  • random (defaults to: nil)

    Random seed or random number generator for reproducible bootstrapping.

  • orient (defaults to: nil)

    Orientation of the plot (:v for vertical, or :h for horizontal).

  • key_color (defaults to: nil)

    Color for all of the elements, or seed for a gradient palette.

  • palette (defaults to: nil)

    Colors to use for the different levels of the color-dimension variable.

  • saturation

    Propotion of the original saturation to draw colors.

  • error_color (defaults to: [0.26, 0.26, 0.26])

    Color for the lines that represent the confidence intervals.

  • error_width (defaults to: nil)

    Thickness of error bar lines (and caps).

  • cap_size (defaults to: nil)

    Width of the caps on error bars.

  • dodge (true, false) (defaults to: true)

    If true, bar position is shifted along the categorical axis for avoid overlapping when the color-dimension is used.

  • log (true, false) (defaults to: false)

    Set the value-axis (e.g. Y-axis if orient is :v) to be log scale.

  • x_label (String, Symbol, #to_str, nil) (defaults to: nil)

    X-axis label.

  • y_label (String, Symbol, #to_str, nil) (defaults to: nil)

    Y-axis label.

  • title (String, Symbol, #to_str, nil) (defaults to: nil)

    Title text.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/charty/plot_methods.rb', line 30

def bar_plot(x: nil, y: nil, color: nil, data: nil,
             order: nil, color_order: nil,
             estimator: :mean, ci: 95, n_boot: 1000, units: nil, random: nil,
             orient: nil, key_color: nil, palette: nil, saturation: 1r,
             error_color: [0.26, 0.26, 0.26], error_width: nil, cap_size: nil,
             dodge: true, log: false, x_label: nil, y_label: nil, title: nil,
             **options, &block)
  Plotters::BarPlotter.new(
    data: data, variables: { x: x, y: y, color: color },
    order: order, orient: orient,
    estimator: estimator, ci: ci, n_boot: n_boot, units: units, random: random,
    color_order: color_order, key_color: key_color, palette: palette, saturation: saturation,
    error_color: error_color, error_width: error_width, cap_size: cap_size,
    dodge: dodge, log: log, x_label: x_label, y_label: y_label, title: title,
    **options, &block
  )
end