draw_bar | R Documentation |
Draw interactive barplots using plotly
draw_bar(
x,
main = NULL,
xlab = NULL,
ylab = NULL,
col = NULL,
alpha = 1,
horizontal = FALSE,
theme = choose_theme(),
palette = rtemis_palette,
barmode = c("group", "relative", "stack", "overlay"),
group_names = NULL,
order_by_val = FALSE,
ylim = NULL,
hovernames = NULL,
feature_names = NULL,
font_size = 16,
annotate = FALSE,
annotate_col = theme[["labs_col"]],
legend = NULL,
legend_col = NULL,
legend_xy = c(1, 1),
legend_orientation = "v",
legend_xanchor = "left",
legend_yanchor = "auto",
hline = NULL,
hline_col = NULL,
hline_width = 1,
hline_dash = "solid",
hline_annotate = NULL,
hline_annotation_x = 1,
margin = list(b = 65, l = 65, t = 50, r = 10, pad = 0),
automargin_x = TRUE,
automargin_y = TRUE,
padding = 0,
displayModeBar = TRUE,
modeBar_file_format = "svg",
filename = NULL,
file_width = 500,
file_height = 500,
file_scale = 1,
verbosity = 0L
)
x |
vector (possibly named), matrix, or data.frame: If matrix or data.frame, rows are groups (can be 1 row), columns are features |
main |
Character: Main plot title. |
xlab |
Character: x-axis label. |
ylab |
Character: y-axis label. |
col |
Color, vector: Color for bars. Default NULL, which will draw
colors from |
alpha |
Float (0, 1]: Transparency for bar colors. |
horizontal |
Logical: If TRUE, plot bars horizontally |
theme |
Theme object. |
palette |
Character: Name of rtemis palette to use. |
barmode |
Character: Type of bar plot to make: "group", "relative", "stack", "overlay". Default = "group". Use "relative" for stacked bars, wich handles negative values correctly, unlike "stack", as of writing. |
group_names |
Character, vector, length = NROW(x): Group names.
Default = NULL, which uses |
order_by_val |
Logical: If TRUE, order bars by increasing value. Only use for single group data. |
ylim |
Float, vector, length 2: y-axis limits. |
hovernames |
Character, vector: Optional character vector to show on hover over each bar. |
feature_names |
Character, vector, length = NCOL(x): Feature names.
Default = NULL, which uses |
font_size |
Float: Font size for all labels. |
annotate |
Logical: If TRUE, annotate stacked bars |
annotate_col |
Color for annotations |
legend |
Logical: If TRUE, draw legend. Default = NULL, and will be turned on if there is more than one feature present |
legend_col |
Color: Legend text color. Default = NULL, determined by theme |
legend_xy |
Numeric, vector, length 2: x and y for plotly's legend |
legend_orientation |
"v" or "h" for vertical or horizontal |
legend_xanchor |
Character: Legend's x anchor: "left", "center", "right", "auto" |
legend_yanchor |
Character: Legend's y anchor: "top", "middle", "bottom", "auto" |
hline |
Float: If defined, draw a horizontal line at this y value. |
hline_col |
Color for |
hline_width |
Float: Width for |
hline_dash |
Character: Type of line to draw: "solid", "dot", "dash", "longdash", "dashdot", or "longdashdot" |
hline_annotate |
Character: Text of horizontal line annotation if
|
hline_annotation_x |
Numeric: x position to place annotation with paper as reference. 0: to the left of the plot area; 1: to the right of the plot area |
margin |
Named list: plot margins. |
automargin_x |
Logical: If TRUE, automatically set x-axis margins |
automargin_y |
Logical: If TRUE, automatically set y-axis margins |
padding |
Integer: N pixels to pad plot. |
displayModeBar |
Logical: If TRUE, show plotly's modebar |
modeBar_file_format |
Character: "svg", "png", "jpeg", "pdf" / any output file type supported by plotly and your system |
filename |
Character: Path to file to save static plot. |
file_width |
Integer: File width in pixels for when |
file_height |
Integer: File height in pixels for when |
file_scale |
Numeric: If saving to file, scale plot by this number |
verbosity |
Integer: Verbosity level. |
plotly
object.
EDG
## Not run:
draw_bar(VADeaths, legend_xy = c(0, 1))
draw_bar(VADeaths, legend_xy = c(1, 1), legend_xanchor = "left")
# simple individual bars
a <- c(4, 7, 2)
draw_bar(a)
# if input is a data.frame, each row is a group and each column is a feature
b <- data.frame(x = c(3, 5, 7), y = c(2, 1, 8), z = c(4, 5, 2))
rownames(b) <- c("Jen", "Ben", "Ren")
draw_bar(b)
# stacked
draw_bar(b, barmode = "stack")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.