Skip to contents

Plot variable importance using plotly

Usage

draw_varimp(
  x,
  names = NULL,
  main = NULL,
  type = c("bar", "line"),
  xlab = NULL,
  ylab = NULL,
  plot_top = 1,
  orientation = "v",
  line_width = 12,
  labelify = TRUE,
  col = NULL,
  alpha = 1,
  palette = rtemis_palette,
  mar = NULL,
  font_size = 16,
  axis_font_size = 14,
  theme = rtemis_theme,
  showlegend = TRUE,
  filename = NULL,
  file_width = 500,
  file_height = 500,
  file_scale = 1,
  ...
)

Arguments

x

Numeric vector: Input.

names

Vector, string: Names of features.

main

Character: Main title.

type

Character: "bar" or "line".

xlab

Character: x-axis label.

ylab

Character: y-axis label.

plot_top

Integer: Plot this many top features.

orientation

Character: "h" or "v".

line_width

Numeric: Line width.

labelify

Logical: If TRUE, labelify feature names.

col

Vector, colors: Single value, or multiple values to define bar (feature) color(s).

alpha

Numeric: Transparency.

palette

Character: Name of rtemis palette to use.

mar

Vector, numeric, length 4: Plot margins in pixels (NOT inches).

font_size

Integer: Overall font size to use (essentially for the title at this point).

axis_font_size

Integer: Font size to use for axis labels and tick labels.

theme

Output of an rtemis theme function (list of parameters) or theme name. Use themes() to print available themes.

showlegend

Logical: If TRUE, show legend.

filename

Character: Path to save the plot image.

file_width

Numeric: Width of the saved plot image.

file_height

Numeric: Height of the saved plot image.

file_scale

Numeric: Scale of the saved plot image.

...

Additional arguments passed to theme.

Value

A plotly object.

Details

A simple plotly wrapper to plot horizontal barplots, sorted by value, which can be used to visualize variable importance, model coefficients, etc.

Author

EDG

Examples

if (FALSE) { # \dontrun{
# made-up data
x <- rnorm(10)
names(x) <- paste0("Feature_", seq(x))
draw_varimp(x)
draw_varimp(x, orientation = "v")
} # }