View source: R/mk_likertplot.R
mk_likertplot | R Documentation |
mk_likertplot
takes a data frame as input and returns a function for
making likert plots (a.k.a., horizontal diverging bar plots) with any
categorical variable from the data frame on the y-axis and the value of
any continuous variable on the x-axis, with bars colored by a 2nd
categorical fillby variable. The resulting plot can have bars ordered from
top to bottom in alphanumerical, ascending or descending order.
mk_likertplot(df)
df |
A data frame. |
function(xvar, yvar, fillby, fillby_lvls, rawcnt_var = NULL,
yorder = NULL, x_as_pct = FALSE,
label_decimals = 1, label_size = 3,
legend_title = fillby, legend_pos = "right",
grid_line_size = 0.4, font_size = 14)
xvar. String, name of a continuous variable for x-axis.
yvar. String, name of a categorical variable for y-axis.
fillby. String, name of a different categorical variable for sub-dividing and coloring the bars.
fillby_lvls. Character vector, levels of fillby variable that the fillby variable should be ordered accordingly.
rawcnt_var. String, name of the variable that contains the raw count behind each tier. Default = NULL because not all input dataframe has such a variable.
yorder String. Possible values: NULL (default), "alphanumeric", "ascend" or "descend". It specifies how categories are ordered on the y-axis. When NULL, the categories are shown in their order in the data.
x_as_pct. Logical, if TRUE, format x-axis as it as comma. Default is FALSE.
label_decimals. Integer, the number of decimal points shown on the bar labels. Default = 1.
label_size. Integer, size of bar label text. Default is 3. Hide bar labels when its value is 0.
legend_title. String, legend title. Default is the name of the fillby variable.
legend_pos. String, legend position. Default = "right".
grid_line_size. Number, the width of vertical grid lines. If 0 (default), the vertical grid lines are hidden.
font_size. Overall font size. Default = 14. The font size of the axes and legend text is a fraction of this value.
scale_axis
for adding different scales to the x-axis.
inst/examples/ex-mk_likertplot.R
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.