Skip to content

Commit

Permalink
Examples updated for ggplot2
Browse files Browse the repository at this point in the history
  • Loading branch information
sherrillmix committed Dec 24, 2015
1 parent f00108b commit 060b634
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 14 deletions.
11 changes: 11 additions & 0 deletions R/geom-beeswarm.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
#' \code{\link[ggplot2]{geom_boxplot}} for another way of looking at the conditional
#' distribution of a variable
#' @export
#' @examples
#'
#' ggplot2::qplot(class, hwy, data = ggplot2::mpg, geom='beeswarm')
#' # Generate fake data
#' distro <- data.frame(
#' 'variable'=rep(c('runif','rnorm'),each=100),
#' 'value'=c(runif(100, min=-3, max=3), rnorm(100))
#' )
#' ggplot2::qplot(variable, value, data = distro, geom='beeswarm')
#' ggplot2::qplot(variable, value, data = distro) +
#' geom_beeswarm(priority='density',cex=2.5)
geom_beeswarm <- function(mapping = NULL, data = NULL,
priority = c("ascending", "descending", "density", "random", "none"),cex=2,groupOnX=NULL,
stat='identity',position = "quasirandom", na.rm = FALSE,
Expand Down
9 changes: 9 additions & 0 deletions R/geom-quasirandom.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
#' \code{\link[ggplot2]{geom_jitter}} for jittered points,
#' \code{\link{geom_boxplot}} for another way of looking at the conditional
#' distribution of a variable
#' @examples
#' ggplot2::qplot(class, hwy, data = ggplot2::mpg, geom='quasirandom')
#' # Generate fake data
#' distro <- data.frame(
#' 'variable'=rep(c('runif','rnorm'),each=100),
#' 'value'=c(runif(100, min=-3, max=3), rnorm(100))
#' )
#' ggplot2::qplot(variable, value, data = distro, geom = 'quasirandom')
#' ggplot2::qplot(variable, value, data = distro) + geom_quasirandom(width=0.1)
#' @export
geom_quasirandom <- function(mapping = NULL, data = NULL,
width = NULL, varwidth = FALSE, bandwidth=.5,nbins=1000,method='quasirandom',groupOnX=NULL,
Expand Down
8 changes: 4 additions & 4 deletions R/position-beeswarm.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
#' @seealso \code{\link{position_quasirandom}}, \code{\link[beeswarm]{swarmx}}
#' @examples
#'
#' ggplot2::qplot(class, hwy, data = ggplot2::mpg, position=position_beeswarm())
#' ggplot2::qplot(class, hwy, data = ggplot2::mpg, geom='beeswarm')
#' # Generate fake data
#' distro <- data.frame(
#' 'variable'=rep(c('runif','rnorm'),each=100),
#' 'value'=c(runif(100, min=-3, max=3), rnorm(100))
#' )
#' ggplot2::qplot(variable, value, data = distro, position = position_beeswarm())
#' ggplot2::qplot(variable, value, data = distro, position =
#' position_beeswarm(priority='density'),cex=2.5)
#' ggplot2::qplot(variable, value, data = distro, geom='beeswarm')
#' ggplot2::qplot(variable, value, data = distro) +
#' geom_beeswarm(priority='density',cex=2.5)
#'
position_beeswarm <- function (priority = c("ascending", "descending", "density", "random", "none"),cex=2,groupOnX=NULL) {
ggplot2::ggproto(NULL,PositionBeeswarm,priority = priority,cex=cex,groupOnX=NULL)
Expand Down
6 changes: 3 additions & 3 deletions R/position-quasirandom.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#' @seealso \code{\link[vipor]{offsetX}}
#' @examples
#'
#' ggplot2::qplot(class, hwy, data = ggplot2::mpg, position=position_quasirandom())
#' ggplot2::qplot(class, hwy, data = ggplot2::mpg, geom='quasirandom')
#' # Generate fake data
#' distro <- data.frame(
#' 'variable'=rep(c('runif','rnorm'),each=100),
#' 'value'=c(runif(100, min=-3, max=3), rnorm(100))
#' )
#' ggplot2::qplot(variable, value, data = distro, position = position_quasirandom())
#' ggplot2::qplot(variable, value, data = distro, position = position_quasirandom(width=0.1))
#' ggplot2::qplot(variable, value, data = distro, geom = 'quasirandom')
#' ggplot2::qplot(variable, value, data = distro) + geom_quasirandom(width=0.1)
#'
position_quasirandom <- function (width = NULL, varwidth = FALSE, bandwidth=.5,nbins=1000,method='quasirandom',groupOnX=NULL) {
ggplot2::ggproto(NULL,PositionQuasirandom,width = width, varwidth = varwidth, bandwidth=bandwidth,nbins=nbins,method=method,groupOnX=groupOnX)
Expand Down
11 changes: 11 additions & 0 deletions man/geom_beeswarm.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ The beeswarm geom is a convenient means to offset points within categories to re

\Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "point")}
}
\examples{
ggplot2::qplot(class, hwy, data = ggplot2::mpg, geom='beeswarm')
# Generate fake data
distro <- data.frame(
'variable'=rep(c('runif','rnorm'),each=100),
'value'=c(runif(100, min=-3, max=3), rnorm(100))
)
ggplot2::qplot(variable, value, data = distro, geom='beeswarm')
ggplot2::qplot(variable, value, data = distro) +
geom_beeswarm(priority='density',cex=2.5)
}
\seealso{
\code{\link{geom_quasirandom}} an alternative method,
\code{\link[beeswarm]{swarmx}} how spacing is determined,
Expand Down
10 changes: 10 additions & 0 deletions man/geom_quasirandom.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ The quasirandom geom is a convenient means to offset points within categories to

\Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "point")}
}
\examples{
ggplot2::qplot(class, hwy, data = ggplot2::mpg, geom='quasirandom')
# Generate fake data
distro <- data.frame(
'variable'=rep(c('runif','rnorm'),each=100),
'value'=c(runif(100, min=-3, max=3), rnorm(100))
)
ggplot2::qplot(variable, value, data = distro, geom = 'quasirandom')
ggplot2::qplot(variable, value, data = distro) + geom_quasirandom(width=0.1)
}
\seealso{
\code{\link[vipor]{offsetX}} how spacing is determined,
\code{\link[ggplot2]{geom_point}} for regular, unjittered points,
Expand Down
8 changes: 4 additions & 4 deletions man/position_beeswarm.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ position_beeswarm(priority = c("ascending", "descending", "density", "random",
Violin point-style plots to show overlapping points. x must be discrete.
}
\examples{
ggplot2::qplot(class, hwy, data = ggplot2::mpg, position=position_beeswarm())
ggplot2::qplot(class, hwy, data = ggplot2::mpg, geom='beeswarm')
# Generate fake data
distro <- data.frame(
'variable'=rep(c('runif','rnorm'),each=100),
'value'=c(runif(100, min=-3, max=3), rnorm(100))
)
ggplot2::qplot(variable, value, data = distro, position = position_beeswarm())
ggplot2::qplot(variable, value, data = distro, position =
position_beeswarm(priority='density'),cex=2.5)
ggplot2::qplot(variable, value, data = distro, geom='beeswarm')
ggplot2::qplot(variable, value, data = distro) +
geom_beeswarm(priority='density',cex=2.5)
}
\seealso{
\code{\link{position_quasirandom}}, \code{\link[beeswarm]{swarmx}}
Expand Down
6 changes: 3 additions & 3 deletions man/position_quasirandom.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ Smaller numbers (< 1) produce a tighter "fit". (default: 0.5)}
Violin point-style plots to show overlapping points. x must be discrete.
}
\examples{
ggplot2::qplot(class, hwy, data = ggplot2::mpg, position=position_quasirandom())
ggplot2::qplot(class, hwy, data = ggplot2::mpg, geom='quasirandom')
# Generate fake data
distro <- data.frame(
'variable'=rep(c('runif','rnorm'),each=100),
'value'=c(runif(100, min=-3, max=3), rnorm(100))
)
ggplot2::qplot(variable, value, data = distro, position = position_quasirandom())
ggplot2::qplot(variable, value, data = distro, position = position_quasirandom(width=0.1))
ggplot2::qplot(variable, value, data = distro, geom = 'quasirandom')
ggplot2::qplot(variable, value, data = distro) + geom_quasirandom(width=0.1)
}
\seealso{
\code{\link[vipor]{offsetX}}
Expand Down

0 comments on commit 060b634

Please sign in to comment.