View source: R/binning_methods.R
bin_dots | R Documentation |
Bins the provided data values using one of several dotplot algorithms.
bin_dots(
x,
y,
binwidth,
heightratio = 1,
stackratio = 1,
layout = c("bin", "weave", "hex", "swarm", "bar"),
side = c("topright", "top", "right", "bottomleft", "bottom", "left", "topleft",
"bottomright", "both"),
orientation = c("horizontal", "vertical", "y", "x"),
overlaps = "nudge"
)
x |
numeric vector of x values |
y |
numeric vector of y values |
binwidth |
bin width |
heightratio |
ratio of bin width to dot height |
stackratio |
ratio of dot height to vertical distance between dot centers |
layout |
The layout method used for the dots:
|
side |
Which side to place the slab on. |
orientation |
Whether the dots are laid out horizontally or vertically.
Follows the naming scheme of
For compatibility with the base ggplot naming scheme for |
overlaps |
How to handle overlapping dots or bins in the
|
A data.frame
with three columns:
x
: the x position of each dot
y
: the y position of each dot
bin
: a unique number associated with each bin
(supplied but not used when layout = "swarm"
)
find_dotplot_binwidth()
for an algorithm that finds good bin widths
to use with this function; geom_dotsinterval()
for geometries that use
these algorithms to create dotplots.
library(dplyr)
library(ggplot2)
x = qnorm(ppoints(20))
bin_df = bin_dots(x = x, y = 0, binwidth = 0.5, heightratio = 1)
bin_df
# we can manually plot the binning above, though this is only recommended
# if you are using find_dotplot_binwidth() and bin_dots() to build your own
# grob. For practical use it is much easier to use geom_dots(), which will
# automatically select good bin widths for you (and which uses
# find_dotplot_binwidth() and bin_dots() internally)
bin_df %>%
ggplot(aes(x = x, y = y)) +
geom_point(size = 4) +
coord_fixed()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.