Skip to content

Fix for issue #825 so that dotplot now works with qplot. #912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
12 changes: 8 additions & 4 deletions R/geom-dotplot.r
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand 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
Expand All @@ -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
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions R/quick-plot.r
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
3 changes: 3 additions & 0 deletions man/geom_dotplot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions man/qplot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}