Draw Distributions using Histograms and Density Plots using plotly
.
Usage
draw_dist(
x,
type = c("density", "histogram"),
mode = c("overlap", "ridge"),
group = NULL,
main = NULL,
xlab = NULL,
ylab = NULL,
col = NULL,
alpha = 0.75,
plot_bg = NULL,
theme = rtemis_theme,
palette = rtemis_palette,
axes_square = FALSE,
group_names = NULL,
font_size = 16,
font_alpha = 0.8,
legend = NULL,
legend_xy = c(0, 1),
legend_col = NULL,
legend_bg = "#FFFFFF00",
legend_border_col = "#FFFFFF00",
bargap = 0.05,
vline = NULL,
vline_col = theme[["fg"]],
vline_width = 1,
vline_dash = "dot",
text = NULL,
text_x = 1,
text_xref = "paper",
text_xanchor = "left",
text_y = 1,
text_yref = "paper",
text_yanchor = "top",
text_col = theme[["fg"]],
margin = list(b = 65, l = 65, t = 50, r = 10, pad = 0),
automargin_x = TRUE,
automargin_y = TRUE,
zerolines = FALSE,
density_kernel = "gaussian",
density_bw = "SJ",
histnorm = c("", "density", "percent", "probability", "probability density"),
histfunc = c("count", "sum", "avg", "min", "max"),
hist_n_bins = 20,
barmode = "overlay",
ridge_sharex = TRUE,
ridge_y_labs = FALSE,
ridge_order_on_mean = TRUE,
displayModeBar = TRUE,
modeBar_file_format = "svg",
width = NULL,
height = NULL,
filename = NULL,
file_width = 500,
file_height = 500,
file_scale = 1,
...
)
Arguments
- x
Numeric vector / data.frame / list: Input. If not a vector, each column / each element is drawn.
- type
Character: "density" or "histogram".
- mode
Character: "overlap", "ridge". How to plot different groups; on the same axes ("overlap"), or on separate plots with the same x-axis ("ridge").
- group
Vector: Will be converted to factor; levels define group members.
- main
Character: Main title for the plot.
- xlab
Character: Label for the x-axis.
- ylab
Character: Label for the y-axis.
- col
Color: Colors for the plot.
- alpha
Numeric: Alpha transparency for plot elements.
- plot_bg
Color: Background color for plot area.
- theme
List: Theme settings for the plot.
- palette
Character: Color palette to use.
- axes_square
Logical: If TRUE, draw a square plot to fill the graphic device. Default = FALSE.
- group_names
Character: Names for the groups.
- font_size
Numeric: Font size for plot text.
- font_alpha
Numeric: Alpha transparency for font.
- legend
Logical: If TRUE, draw legend. Default = NULL, which will be set to TRUE if x is a list of more than 1 element.
- legend_xy
Numeric, vector, length 2: Relative x, y position for legend. Default = c(0, 1).
- legend_col
Color: Color for the legend text.
- legend_bg
Color: Background color for legend.
- legend_border_col
Color: Border color for legend.
- bargap
Numeric: The gap between adjacent histogram bars in plot fraction.
- vline
Numeric, vector: If defined, draw a vertical line at this x value(s).
- vline_col
Color: Color for
vline
.- vline_width
Numeric: Width for
vline
.- vline_dash
Character: Type of line to draw: "solid", "dot", "dash", "longdash", "dashdot", or "longdashdot".
- text
Character: If defined, add this text over the plot.
- text_x
Numeric: x-coordinate for
text
.- text_xref
Character: "x":
text_x
refers to plot's x-axis; "paper":text_x
refers to plotting area from 0-1.- text_xanchor
Character: "auto", "left", "center", "right".
- text_y
Numeric: y-coordinate for
text
.- text_yref
Character: "y":
text_y
refers to plot's y-axis; "paper":text_y
refers to plotting area from 0-1.- text_yanchor
Character: "auto", "top", "middle", "bottom".
- text_col
Color: Color for
text
.- margin
List: Margins for the plot.
- automargin_x
Logical: If TRUE, automatically adjust x-axis margins.
- automargin_y
Logical: If TRUE, automatically adjust y-axis margins.
- zerolines
Logical: If TRUE, draw lines at y = 0.
- density_kernel
Character: Kernel to use for density estimation.
- density_bw
Character: Bandwidth to use for density estimation.
- histnorm
Character: NULL, "percent", "probability", "density", "probability density".
- histfunc
Character: "count", "sum", "avg", "min", "max".
- hist_n_bins
Integer: Number of bins to use if type = "histogram".
- barmode
Character: Barmode for histogram. Default = "overlay".
Logical: If TRUE, draw single x-axis when
mode = "ridge"
.- ridge_y_labs
Logical: If TRUE, show individual y labels when
mode = "ridge"
.- ridge_order_on_mean
Logical: If TRUE, order groups by mean value when
mode = "ridge"
.- displayModeBar
Logical: If TRUE, display the mode bar.
- modeBar_file_format
Character: File format for mode bar. Default = "svg".
- width
Numeric: Force plot size to this width. Default = NULL, i.e. fill available space.
- height
Numeric: Force plot size to this height. Default = NULL, i.e. fill available space.
- filename
Character: Path to file to save static plot.
- file_width
Integer: File width in pixels for when
filename
is set.- file_height
Integer: File height in pixels for when
filename
is set.- file_scale
Numeric: If saving to file, scale plot by this number.
- ...
Additional arguments passed to theme function.
Examples
if (FALSE) { # \dontrun{
draw_dist(iris)
draw_dist(split(iris[["Sepal.Length"]], iris[["Species"]]), xlab = "Sepal Length")
} # }