Skip to contents

Wrapper for plotly::plot_ly for shorthand declaration of many layout and trace arguments. Ensures proper scaling or elements when used in shiny apps, iframes, static image downloads and so on.

Usage

roboplot(
  d,
  color = NULL,
  title = NULL,
  subtitle = "",
  caption = NULL,
  legend_orientation = NULL,
  legend_position = NULL,
  trace_color = NULL,
  highlight = NULL,
  zeroline = FALSE,
  rangeslider = FALSE,
  pattern = NULL,
  line_width = getOption("roboplot.linewidth"),
  hovertext = NULL,
  plot_type = "scatter",
  plot_mode = NULL,
  plot_axes = set_axes(),
  markers = set_markers(),
  height = getOption("roboplot.height"),
  error_bars = NULL,
  facet_split = NULL,
  legend_maxwidth = NULL,
  xaxis_ceiling = getOption("roboplot.xaxis.ceiling"),
  width = getOption("roboplot.width"),
  legend_title = F,
  shadearea = NULL,
  secondary_yaxis = NULL,
  modebar = NULL,
  artefacts = getOption("roboplot.artefacts")$auto,
  container = getOption("roboplot.shinyapp")$container,
  info_text = NULL,
  tidy_legend = getOption("roboplot.legend.tidy"),
  ...
)

Arguments

d

Data frame. Data to be plotted with at least the columns "time" (Date or POSIXt) and "value" (numeric). Other columns could be specified instead with 'plot_axes', using set_axes().

color

Symbol, string, or function resulting in symbol or string. Column from param 'd' to use for trace color. If NULL, the argument 'subtitle' will be used as a placeholder for determining color and hoverlabels.

title, subtitle

Characters. Labels for plot elements. Optionally, use set_title() for the title if you want to omit the title from the displayed plot, but include it for any downloads through the modebar.

caption

Function or character. Use set_caption().

legend_position, legend_orientation

Characters. Currently only legend_position is used, and takes only "bottom" or NA for no legend. Legend is removed on default if the argument 'color' in argument 'd' has only one observation.

trace_color

Character vector, named if length > 1. Trace colors for all traces. Determines the trace type for either the whole plot, or for all variables defined by param 'color' as name-value pairs.

highlight

Numeric or list. Determines if a given trace is included in legend and assigned a color. If numeric, traces with max(value) < highlight will be give trace color matching the grid color, and removed from the legend. If function, it must return a logical and include named items "value" and ".fun", where .fun checks if given value will get a color or legend item. Will not currently work with multiple patterns.

zeroline

Logical or numeric. Determines zeroline inclusion, TRUE for zeroline, or numeric for exact placement.

rangeslider

Logical or character in %Y-%m-%d format. Determines rangeslider inclusion. TRUE includes the rangeslider, a character string includes the rangeslider with the given date as a start date.

pattern

Symbol, string, or function resulting in symbol or string. Optionally, use set_pattern() for more fine-tuned control. See documentation of that function. Column from param 'd' to use for scatter plot linetype or bar plot pattern. Not supported for pie charts.

line_width

Numeric vector, named if length > 1. Line width for all line traces. Determines the line width for either the whole plot, or for all variables contained in the column defined by param 'color' as name-value pairs.

hovertext

Function. Use set_hovertext().

plot_type

Character vector, named if length > 1. Determines the trace type for either the whole plot, or for all variables defined by color as name-value pairs.

plot_mode

Character vector, named if length > 1. Controls plot specifics along with the parameter 'plot_type'. When 'plot_type' is "scatter", the available modes are "line" "scatter", "smooth", "step" and "scatter+line". When 'plot_type' is "bar", the available modes are "dodge" "stack", "horizontal", "horizontalfill" and "horizontalstack". Mode of "horizontalfill" makes bars fill the space available is observations are missing. When 'plot_type' is "pie", the available modes are "normal" and "rotated". You can give a single unnamed 'plot_mode' which is used as applicable, or name-value pairs, where names are items from parameter 'd' column described by parameter 'color', and values applicable plot modes listed above.

plot_axes

Function. Use set_axes().

markers

Function. Use set_markers(). Marker appearance for all markers.

height, width

Numeric. Height and width of the plot. Default width is NA for responsive plots, give a value for static plot width.

error_bars

Function. Use set_errorbars(). Specifications for any error bars.

facet_split

Currently unused. Variable from argument 'd' to use for facet splits.

legend_maxwidth

Numeric. Legend items (and y-axis values for horizontal barplots) longer than this will be collapsed with an ellipsis.

xaxis_ceiling

Character or date. One of "default", "days", "months", "weeks", "quarters", "years", or "guess"). Set, or round, the upper bound of plot x-axis for other than bar plots if no axis limits are given.

legend_title

Logical or character. Use TRUE if you want the parameter 'color' to be the legend title. Use a character string if you want to provide your own legend title.

shadearea

Use if you want to have a highlighted area on the roboplot(). Use set_shadearea() for fine-tuned control (see that function for documentation), or provide a single value that corresponds with the x-axis of the plot. Currently only useful when x-axis is numeric or date, and y-axis is numeric.

secondary_yaxis

Character vector. Observations from param 'color' of roboplot which will use a secondary y-axis. Parameter 'zeroline' will be ignored. Use param 'plot_axes' with set_axes() for more control over secondary yaxis (see documentation for several examples.)

modebar

Function. Use set_modebar().

artefacts

Logical or function. Use set_artefacts() for fine-tuned control. Use TRUE instead for automated artefact creation or html and/or other files from the plot based on settings globally set by set_roboplot_options().

container

Character. Experimental, might not work as intended. Use only with shiny apps. A css selector for the element in a shiny app where this roboplot() will be contained in. Used for relayouts if the plot is rendered while the container is not displayed.

info_text

Character. If provided, an info button is appended to the modebar of roboplot() which brings about a popup with this parameter as the text content, along with plot title and caption elements.

tidy_legend

Logical. Controls whether the legend items will have matching widths, making for neater legends, or containing text widths, saving space. Default is FALSE.

...

Placeholder for other parameters.

Value

A list of classes "plotly" and "html"

Examples