Skip to content

Commit ae175ae

Browse files
committed
Merge pull request #912 from rasmusab/dotplot-qplot-fix
Fix for issue #825 so that dotplot now works with qplot.
2 parents a6b65b3 + da4ac69 commit ae175ae

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ ggplot2 0.9.3.1.99
55
calculation of the other limit by passing NA to to the limit function,
66
`xlim()` or `ylim()` (@jimhester, #557).
77

8+
* `geom_dotplot` now works with qplot. (@rasmusab. Fixes #825)
9+
810
* `stat_smooth()` checks for `method = "auto"` and `method = "glm"` in
911
a safer way.
1012

R/geom-dotplot.r

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@
9595
#'
9696
#' ggplot(mtcars, aes(x = 1, y = mpg, fill = factor(cyl))) +
9797
#' geom_dotplot(binaxis = "y", stackgroups = TRUE, binwidth = 1, method = "histodot")
98+
#'
99+
#' # Use qplot instead
100+
#' qplot(mpg, data = mtcars, geom = "dotplot")
98101
#'
99102
geom_dotplot <- function (mapping = NULL, data = NULL, stat = "bindot", position = "identity",
100103
na.rm = FALSE, binwidth = NULL, binaxis = "x", method="dotdensity", binpositions = "bygroup", stackdir = "up",
@@ -152,7 +155,7 @@ GeomDotplot <- proto(Geom, {
152155
params$width %||% (resolution(df$x, FALSE) * 0.9)
153156

154157
# Set up the stacking function and range
155-
if(params$stackdir == "up") {
158+
if(is.null(params$stackdir) || params$stackdir == "up") {
156159
stackdots <- function(a) a - .5
157160
stackaxismin <- 0
158161
stackaxismax <- 1
@@ -176,8 +179,9 @@ GeomDotplot <- proto(Geom, {
176179

177180
# Next part will set the position of each dot within each stack
178181
# If stackgroups=TRUE, split only on x (or y) and panel; if not stacking, also split by group
179-
plyvars <- c(params$binaxis, "PANEL")
180-
if (!params$stackgroups)
182+
plyvars <- params$binaxis %||% "x"
183+
plyvars <- c(plyvars, "PANEL")
184+
if (is.null(params$stackgroups) || !params$stackgroups)
181185
plyvars <- c(plyvars, "group")
182186

183187
# Within each x, or x+group, set countidx=1,2,3, and set stackpos according to stack function
@@ -189,7 +193,7 @@ GeomDotplot <- proto(Geom, {
189193

190194

191195
# Set the bounding boxes for the dots
192-
if (params$binaxis == "x") {
196+
if (is.null(params$binaxis) || params$binaxis == "x") {
193197
# ymin, ymax, xmin, and xmax define the bounding rectangle for each stack
194198
# Can't do bounding box per dot, because y position isn't real.
195199
# After position code is rewritten, each dot should have its own bounding box.

R/quick-plot.r

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#' # Use different geoms
7474
#' qplot(mpg, wt, data = mtcars, geom="path")
7575
#' qplot(factor(cyl), wt, data = mtcars, geom=c("boxplot", "jitter"))
76+
#' qplot(mpg, data = mtcars, geom = "dotplot")
7677
#' }
7778
qplot <- function(x, y = NULL, ..., data, facets = NULL, margins=FALSE, geom = "auto", stat=list(NULL), position=list(NULL), xlim = c(NA, NA), ylim = c(NA, NA), log = "", main = NULL, xlab = deparse(substitute(x)), ylab = deparse(substitute(y)), asp = NA) {
7879

man/geom_dotplot.Rd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ ggplot(mtcars, aes(x = mpg, fill = factor(cyl))) +
139139

140140
ggplot(mtcars, aes(x = 1, y = mpg, fill = factor(cyl))) +
141141
geom_dotplot(binaxis = "y", stackgroups = TRUE, binwidth = 1, method = "histodot")
142+
143+
# Use qplot instead
144+
qplot(mpg, data = mtcars, geom = "dotplot")
142145
}
143146
\references{
144147
Wilkinson, L. (1999) Dot plots. The American Statistician,

man/qplot.Rd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ qplot(y = mpg, data = mtcars)
107107
# Use different geoms
108108
qplot(mpg, wt, data = mtcars, geom="path")
109109
qplot(factor(cyl), wt, data = mtcars, geom=c("boxplot", "jitter"))
110+
qplot(mpg, data = mtcars, geom = "dotplot")
110111
}
111112
}
112113

0 commit comments

Comments
 (0)