diff --git a/NEWS b/NEWS index f29adca4de..83719560d7 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ ggplot2 0.9.3.1.99 calculation of the other limit by passing NA to to the limit function, `xlim()` or `ylim()` (@jimhester, #557). +* `geom_dotplot` now works with qplot. (@rasmusab. Fixes #825) + * `stat_smooth()` checks for `method = "auto"` and `method = "glm"` in a safer way. diff --git a/R/geom-dotplot.r b/R/geom-dotplot.r index 757fbe5160..cb18094164 100644 --- a/R/geom-dotplot.r +++ b/R/geom-dotplot.r @@ -95,6 +95,9 @@ #' #' ggplot(mtcars, aes(x = 1, y = mpg, fill = factor(cyl))) + #' geom_dotplot(binaxis = "y", stackgroups = TRUE, binwidth = 1, method = "histodot") +#' +#' # Use qplot instead +#' qplot(mpg, data = mtcars, geom = "dotplot") #' geom_dotplot <- function (mapping = NULL, data = NULL, stat = "bindot", position = "identity", na.rm = FALSE, binwidth = NULL, binaxis = "x", method="dotdensity", binpositions = "bygroup", stackdir = "up", @@ -152,7 +155,7 @@ GeomDotplot <- proto(Geom, { params$width %||% (resolution(df$x, FALSE) * 0.9) # Set up the stacking function and range - if(params$stackdir == "up") { + if(is.null(params$stackdir) || params$stackdir == "up") { stackdots <- function(a) a - .5 stackaxismin <- 0 stackaxismax <- 1 @@ -176,8 +179,9 @@ GeomDotplot <- proto(Geom, { # Next part will set the position of each dot within each stack # If stackgroups=TRUE, split only on x (or y) and panel; if not stacking, also split by group - plyvars <- c(params$binaxis, "PANEL") - if (!params$stackgroups) + plyvars <- params$binaxis %||% "x" + plyvars <- c(plyvars, "PANEL") + if (is.null(params$stackgroups) || !params$stackgroups) plyvars <- c(plyvars, "group") # 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, { # Set the bounding boxes for the dots - if (params$binaxis == "x") { + if (is.null(params$binaxis) || params$binaxis == "x") { # ymin, ymax, xmin, and xmax define the bounding rectangle for each stack # Can't do bounding box per dot, because y position isn't real. # After position code is rewritten, each dot should have its own bounding box. diff --git a/R/quick-plot.r b/R/quick-plot.r index 7538e4ff07..b1fd2dceb1 100644 --- a/R/quick-plot.r +++ b/R/quick-plot.r @@ -73,6 +73,7 @@ #' # Use different geoms #' qplot(mpg, wt, data = mtcars, geom="path") #' qplot(factor(cyl), wt, data = mtcars, geom=c("boxplot", "jitter")) +#' qplot(mpg, data = mtcars, geom = "dotplot") #' } 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) { diff --git a/man/geom_dotplot.Rd b/man/geom_dotplot.Rd index da1f0a1bdc..7940572d7a 100644 --- a/man/geom_dotplot.Rd +++ b/man/geom_dotplot.Rd @@ -139,6 +139,9 @@ ggplot(mtcars, aes(x = mpg, fill = factor(cyl))) + ggplot(mtcars, aes(x = 1, y = mpg, fill = factor(cyl))) + geom_dotplot(binaxis = "y", stackgroups = TRUE, binwidth = 1, method = "histodot") + +# Use qplot instead +qplot(mpg, data = mtcars, geom = "dotplot") } \references{ Wilkinson, L. (1999) Dot plots. The American Statistician, diff --git a/man/qplot.Rd b/man/qplot.Rd index cbf5606090..94187f6678 100644 --- a/man/qplot.Rd +++ b/man/qplot.Rd @@ -107,6 +107,7 @@ qplot(y = mpg, data = mtcars) # Use different geoms qplot(mpg, wt, data = mtcars, geom="path") qplot(factor(cyl), wt, data = mtcars, geom=c("boxplot", "jitter")) +qplot(mpg, data = mtcars, geom = "dotplot") } }