Description Usage Arguments Value Examples
Calculate the (weighted) average value of a binned set of data, and plot it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | binned_one_way_data(
x,
yData,
weight = rep(1, length(x)),
scaleWeight = TRUE,
type = "quantile",
bins = 10
)
binned_one_way_plot(
x,
yData,
weight = rep(1, length(x)),
scaleWeight = TRUE,
type = "quantile",
bins = 10,
fontSize = 10,
showWeights = TRUE,
plotly = FALSE,
bgColor = "#CCDDFF",
xlab = "Bins",
ylab = "Response",
wlab = "Weight",
title = paste("One-Way Plot", if (!missing(xlab)) paste0("of ", xlab), if
(!missing(ylab)) paste0("by ", ylab))
)
|
x |
The vector to perform binning by.
If numeric, it will be binned according to |
yData |
A data.frame-like object (or numeric vector) whose numerical columns will be used to calculate average values by bin. Must have the same number of rows (or length) as the length of x. |
weight |
An (optional) vector of weights for weighted binning, and for taking weighted averages. Must be the same length as x. |
scaleWeight |
If |
type |
The type of binning desired.
Valid options are:
|
bins |
The number of bins to create (or, if |
fontSize |
Size of the font to use in the plot. |
showWeights |
If |
plotly |
Will return a |
bgColor |
Color to use for the background of the plot. |
xlab |
The x-axis label of the plot. |
ylab |
The y-axis label of the data section of the plot. |
wlab |
The y-axis label of the weight section of the plot. |
title |
The title of the plot. |
binned_one_way_data
: a data.table
holding the binned data.
binned_one_way_plot
: a ggplot
object, or a plotly
object if plotly
is TRUE
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | diamonds <- data.table::data.table(ggplot2::diamonds)
binnedData1 <- binned_one_way_data(diamonds[, carat], diamonds[, .(x = x + 0.5, y, z)],
diamonds[, price])
binnedData2 <- binned_one_way_data(diamonds[, carat], diamonds[, .(x = x + 0.5, y, z)],
diamonds[, price], scaleWeight = FALSE)
binnedData3 <- binned_one_way_data(diamonds[, carat], diamonds[, .(x = x + 0.5, y, z)],
diamonds[, price], type = "equal")
binnedData4 <- binned_one_way_data(diamonds[, carat], diamonds[, .(x = x + 0.5, y, z)],
diamonds[, price], bins = 5)
binnedPlot1 <- binned_one_way_plot(diamonds[, carat], diamonds[, .(x = x + 0.5, y, z)],
diamonds[, price])
binnedPlot2 <- binned_one_way_plot(diamonds[, carat], diamonds[, .(x = x + 0.5, y, z)],
diamonds[, price], scaleWeight = FALSE)
binnedPlot3 <- binned_one_way_plot(diamonds[, carat], diamonds[, .(x = x + 0.5, y, z)],
diamonds[, price], type = "equal")
binnedPlot4 <- binned_one_way_plot(diamonds[, carat], diamonds[, .(x = x + 0.5, y, z)],
diamonds[, price], bins = 5)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.