Skip to content

Commit a1827a1

Browse files
committed
StatBinDot and GeomDotPlot need to be tightly coupled
Closes #1194
1 parent ac40d16 commit a1827a1

File tree

5 files changed

+57
-99
lines changed

5 files changed

+57
-99
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ export(scale_y_sqrt)
455455
export(should_stop)
456456
export(stat_bin)
457457
export(stat_bin2d)
458-
export(stat_bindot)
459458
export(stat_binhex)
460459
export(stat_boxplot)
461460
export(stat_contour)

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
ggplot2 1.0.1.9xxx
22
----------------------------------------------------------------
33

4+
* `stat_bindot()` has been removed because it's so tightly coupled to
5+
`geom_dotplot()`. If you happened to use `stat_bindot()`, just change to
6+
`geom_dotplot()` (#1194).
7+
48
* Character labels in `facet_grid()` are no longer (incorrectly) coerced into
59
factors. This caused problems with custom label functions (#1070).
610

R/geom-dotplot.r

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "dotplot")}
2121
#'
2222
#' @inheritParams geom_point
23-
#' @param geom,stat Use to override the default connection between
24-
#' \code{geom_dotplot} and \code{stat_bindot}.
2523
#' @param stackdir which direction to stack the dots. "up" (default),
2624
#' "down", "center", "centerwhole" (centered, but with dots aligned)
2725
#' @param stackratio how close to stack the dots. Default is 1, where dots just
@@ -30,6 +28,34 @@
3028
#' @param stackgroups should dots be stacked across groups? This has the effect
3129
#' that \code{position = "stack"} should have, but can't (because this geom has
3230
#' some odd properties).
31+
#' @param binaxis The axis to bin along, "x" (default) or "y"
32+
#' @param method "dotdensity" (default) for dot-density binning, or
33+
#' "histodot" for fixed bin widths (like stat_bin)
34+
#' @param binwidth When \code{method} is "dotdensity", this specifies maximum bin
35+
#' width. When \code{method} is "histodot", this specifies bin width.
36+
#' Defaults to 1/30 of the range of the data
37+
#' @param binpositions When \code{method} is "dotdensity", "bygroup" (default)
38+
#' determines positions of the bins for each group separately. "all" determines
39+
#' positions of the bins with all the data taken together; this is used for
40+
#' aligning dot stacks across multiple groups.
41+
#' @param origin When \code{method} is "histodot", origin of first bin
42+
#' @param right When \code{method} is "histodot", should intervals be closed
43+
#' on the right (a, b], or not [a, b)
44+
#' @param width When \code{binaxis} is "y", the spacing of the dot stacks
45+
#' for dodging.
46+
#' @param na.rm If \code{FALSE} (the default), removes missing values with
47+
#' a warning. If \code{TRUE} silently removes missing values.
48+
#' @param drop If TRUE, remove all bins with zero counts
49+
#' @return New data frame with additional columns:
50+
#' \item{x}{center of each bin, if binaxis is "x"}
51+
#' \item{y}{center of each bin, if binaxis is "x"}
52+
#' \item{binwidth}{max width of each bin if method is "dotdensity";
53+
#' width of each bin if method is "histodot"}
54+
#' \item{count}{number of points in bin}
55+
#' \item{ncount}{count, scaled to maximum of 1}
56+
#' \item{density}{density of points in bin, scaled to integrate to 1,
57+
#' if method is "histodot"}
58+
#' \item{ndensity}{density, scaled to maximum of 1, if method is "histodot"}
3359
#' @export
3460
#' @references Wilkinson, L. (1999) Dot plots. The American Statistician,
3561
#' 53(3), 276-281.
@@ -57,7 +83,6 @@
5783
#' # Expand dot diameter
5884
#' ggplot(mtcars, aes(x = mpg)) + geom_dotplot(binwidth = 1.5, dotsize = 1.25)
5985
#'
60-
#'
6186
#' # Examples with stacking along y axis instead of x
6287
#' ggplot(mtcars, aes(x = 1, y = mpg)) +
6388
#' geom_dotplot(binaxis = "y", stackdir = "center")
@@ -84,11 +109,11 @@
84109
#'
85110
#' ggplot(mtcars, aes(x = 1, y = mpg, fill = factor(cyl))) +
86111
#' geom_dotplot(binaxis = "y", stackgroups = TRUE, binwidth = 1, method = "histodot")
87-
#'
88-
geom_dotplot <- function (mapping = NULL, data = NULL, stat = "bindot",
112+
geom_dotplot <- function(mapping = NULL, data = NULL,
89113
position = "identity", na.rm = FALSE, binwidth = NULL, binaxis = "x",
90114
method = "dotdensity", binpositions = "bygroup", stackdir = "up",
91-
stackratio = 1, dotsize = 1, stackgroups = FALSE, show_guide = NA,
115+
stackratio = 1, dotsize = 1, stackgroups = FALSE,
116+
origin = NULL, right = TRUE, width = 0.9, drop = FALSE, show_guide = NA,
92117
inherit.aes = TRUE, ...)
93118
{
94119
# If identical(position, "stack") or position is position_stack(), tell them
@@ -104,7 +129,7 @@ geom_dotplot <- function (mapping = NULL, data = NULL, stat = "bindot",
104129
layer(
105130
data = data,
106131
mapping = mapping,
107-
stat = stat,
132+
stat = StatBindot,
108133
geom = GeomDotplot,
109134
position = position,
110135
show_guide = show_guide,
@@ -115,7 +140,11 @@ geom_dotplot <- function (mapping = NULL, data = NULL, stat = "bindot",
115140
na.rm = na.rm,
116141
binwidth = binwidth,
117142
binpositions = binpositions,
118-
method = method
143+
method = method,
144+
origin = origin,
145+
right = right,
146+
width = width,
147+
drop = drop
119148
),
120149
geom_params = list(
121150
binaxis = binaxis,

R/stat-bindot.r

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,3 @@
1-
#' @inheritParams stat_identity
2-
#' @param binaxis The axis to bin along, "x" (default) or "y"
3-
#' @param method "dotdensity" (default) for dot-density binning, or
4-
#' "histodot" for fixed bin widths (like stat_bin)
5-
#' @param binwidth When \code{method} is "dotdensity", this specifies maximum bin
6-
#' width. When \code{method} is "histodot", this specifies bin width.
7-
#' Defaults to 1/30 of the range of the data
8-
#' @param binpositions When \code{method} is "dotdensity", "bygroup" (default)
9-
#' determines positions of the bins for each group separately. "all" determines
10-
#' positions of the bins with all the data taken together; this is used for
11-
#' aligning dot stacks across multiple groups.
12-
#' @param origin When \code{method} is "histodot", origin of first bin
13-
#' @param right When \code{method} is "histodot", should intervals be closed
14-
#' on the right (a, b], or not [a, b)
15-
#' @param width When \code{binaxis} is "y", the spacing of the dot stacks
16-
#' for dodging.
17-
#' @param na.rm If \code{FALSE} (the default), removes missing values with
18-
#' a warning. If \code{TRUE} silently removes missing values.
19-
#' @param drop If TRUE, remove all bins with zero counts
20-
#'
21-
#' @return New data frame with additional columns:
22-
#' \item{x}{center of each bin, if binaxis is "x"}
23-
#' \item{y}{center of each bin, if binaxis is "x"}
24-
#' \item{binwidth}{max width of each bin if method is "dotdensity";
25-
#' width of each bin if method is "histodot"}
26-
#' \item{count}{number of points in bin}
27-
#' \item{ncount}{count, scaled to maximum of 1}
28-
#' \item{density}{density of points in bin, scaled to integrate to 1,
29-
#' if method is "histodot"}
30-
#' \item{ndensity}{density, scaled to maximum of 1, if method is "histodot"}
31-
#' @export
32-
#' @rdname geom_dotplot
33-
stat_bindot <- function (mapping = NULL, data = NULL, geom = "dotplot",
34-
position = "identity", binwidth = NULL, origin = NULL, width = 0.9,
35-
binaxis = "x", method = "dotdensity", binpositions = "bygroup", drop = FALSE,
36-
right = TRUE, na.rm = FALSE, show_guide = NA, inherit.aes = TRUE, ...)
37-
{
38-
layer(
39-
data = data,
40-
mapping = mapping,
41-
stat = StatBindot,
42-
geom = geom,
43-
position = position,
44-
show_guide = show_guide,
45-
inherit.aes = inherit.aes,
46-
stat_params = list(
47-
binaxis = binaxis,
48-
na.rm = na.rm,
49-
binwidth = binwidth,
50-
origin = origin,
51-
width = width,
52-
binpositions = binpositions,
53-
method = method
54-
),
55-
geom_params = list(
56-
binaxis = binaxis,
57-
na.rm = na.rm
58-
),
59-
params = list(...)
60-
)
61-
}
62-
63-
641
#' @rdname ggplot2-ggproto
652
#' @format NULL
663
#' @usage NULL

man/geom_dotplot.Rd

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
% Generated by roxygen2 (4.1.1): do not edit by hand
2-
% Please edit documentation in R/geom-dotplot.r, R/stat-bindot.r
2+
% Please edit documentation in R/geom-dotplot.r
33
\name{geom_dotplot}
44
\alias{geom_dotplot}
5-
\alias{stat_bindot}
65
\title{Dot plot}
76
\usage{
8-
geom_dotplot(mapping = NULL, data = NULL, stat = "bindot",
9-
position = "identity", na.rm = FALSE, binwidth = NULL, binaxis = "x",
10-
method = "dotdensity", binpositions = "bygroup", stackdir = "up",
11-
stackratio = 1, dotsize = 1, stackgroups = FALSE, show_guide = NA,
12-
inherit.aes = TRUE, ...)
13-
14-
stat_bindot(mapping = NULL, data = NULL, geom = "dotplot",
15-
position = "identity", binwidth = NULL, origin = NULL, width = 0.9,
16-
binaxis = "x", method = "dotdensity", binpositions = "bygroup",
17-
drop = FALSE, right = TRUE, na.rm = FALSE, show_guide = NA,
18-
inherit.aes = TRUE, ...)
7+
geom_dotplot(mapping = NULL, data = NULL, position = "identity",
8+
na.rm = FALSE, binwidth = NULL, binaxis = "x", method = "dotdensity",
9+
binpositions = "bygroup", stackdir = "up", stackratio = 1,
10+
dotsize = 1, stackgroups = FALSE, origin = NULL, right = TRUE,
11+
width = 0.9, drop = FALSE, show_guide = NA, inherit.aes = TRUE, ...)
1912
}
2013
\arguments{
2114
\item{mapping}{The aesthetic mapping, usually constructed with
@@ -57,6 +50,16 @@ just touch. Use smaller values for closer, overlapping dots.}
5750
that \code{position = "stack"} should have, but can't (because this geom has
5851
some odd properties).}
5952
53+
\item{origin}{When \code{method} is "histodot", origin of first bin}
54+
55+
\item{right}{When \code{method} is "histodot", should intervals be closed
56+
on the right (a, b], or not [a, b)}
57+
58+
\item{width}{When \code{binaxis} is "y", the spacing of the dot stacks
59+
for dodging.}
60+
61+
\item{drop}{If TRUE, remove all bins with zero counts}
62+
6063
\item{show_guide}{logical. Should this layer be included in the legends?
6164
\code{NA}, the default, includes if any aesthetics are mapped.
6265
\code{FALSE} never includes, and \code{TRUE} always includes.}
@@ -76,19 +79,6 @@ the default plot specification, e.g. \code{\link{borders}}.}
7679
default \code{stat} associated with the layer.
7780
\item Other arguments passed on to the stat.
7881
}}
79-
80-
\item{geom,stat}{Use to override the default connection between
81-
\code{geom_dotplot} and \code{stat_bindot}.}
82-
83-
\item{origin}{When \code{method} is "histodot", origin of first bin}
84-
85-
\item{width}{When \code{binaxis} is "y", the spacing of the dot stacks
86-
for dodging.}
87-
88-
\item{drop}{If TRUE, remove all bins with zero counts}
89-
90-
\item{right}{When \code{method} is "histodot", should intervals be closed
91-
on the right (a, b], or not [a, b)}
9282
}
9383
\value{
9484
New data frame with additional columns:
@@ -148,7 +138,6 @@ ggplot(mtcars, aes(x = mpg)) + geom_dotplot(binwidth = 1.5, stackratio = .7)
148138
# Expand dot diameter
149139
ggplot(mtcars, aes(x = mpg)) + geom_dotplot(binwidth = 1.5, dotsize = 1.25)
150140

151-
152141
# Examples with stacking along y axis instead of x
153142
ggplot(mtcars, aes(x = 1, y = mpg)) +
154143
geom_dotplot(binaxis = "y", stackdir = "center")

0 commit comments

Comments
 (0)