Skip to content

Commit

Permalink
position_violinPoint --> position_quasirandom
Browse files Browse the repository at this point in the history
  • Loading branch information
eclarke committed Oct 15, 2015
1 parent ed12bfd commit 75619d4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Expand Up @@ -3,5 +3,5 @@
export(digits2number)
export(number2digits)
export(offset_x)
export(position_violinPoint)
export(position_quasirandom)
export(vanDerCorput)
22 changes: 11 additions & 11 deletions R/position-violinPoint.R → R/position-quasirandom.R
@@ -1,32 +1,32 @@
#' Violin point-style plots to show overlapping points. x must be discrete.
#'
#' @family position adjustments
#' @name position_violinPoint
#' @name position_quasirandom
#' @param width the maximum amount of spread (default: 0.4)
#' @param varwidth vary the width by the relative size of each group
#' @param bandwidth the bandwidth adjustment to use when calculating density
#' Smaller numbers (< 1) produce a tighter "fit". (default: 0.5)
#' @usage position_violinPoint(width = NULL, varwidth = NULL, bandwidth = NULL)
#' @usage position_quasirandom(width = NULL, varwidth = NULL, bandwidth = NULL)
#' @export
#' @examples
#'
#' if(requireNamespace("ggplot2",quietly=TRUE)&requireNamespace("proto",quietly=TRUE)){
#' # ggplot2::qplot(class, hwy, data = ggplot2::mpg, position=position_violinPoint())
#' # ggplot2::qplot(class, hwy, data = ggplot2::mpg, position=position_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_violinPoint())
#' # ggplot2::qplot(variable, value, data = distro, position = position_violinPoint(width=0.1))
#' # ggplot2::qplot(variable, value, data = distro, position = position_quasirandom())
#' # ggplot2::qplot(variable, value, data = distro, position = position_quasirandom(width=0.1))
#' }
if(requireNamespace("ggplot2",quietly=TRUE)&requireNamespace("proto",quietly=TRUE)){
position_violinPoint <- function (width = NULL, varwidth = NULL, bandwidth=NULL) {
PositionViolinPoint$new(width = width, varwidth = varwidth, bandwidth=bandwidth)
position_quasirandom <- function (width = NULL, varwidth = NULL, bandwidth=NULL) {
PositionQuasirandom$new(width = width, varwidth = varwidth, bandwidth=bandwidth)
}

PositionViolinPoint <- proto::proto(ggplot2:::Position, {
objname <- "violinPoint"
PositionQuasirandom <- proto::proto(ggplot2:::Position, {
objname <- "quasirandom"

new <- function(., width=NULL, varwidth=NULL, bandwidth=NULL) {
.$proto(width=width, varwidth=varwidth, bandwidth=bandwidth)
Expand All @@ -35,7 +35,7 @@ if(requireNamespace("ggplot2",quietly=TRUE)&requireNamespace("proto",quietly=TRU
# Adjust function is used to calculate new positions (from ggplot2:::Position)
adjust <- function(., data) {
if (empty(data)) return(data.frame())
check_required_aesthetics(c("x", "y"), names(data), "position_violinPoint")
check_required_aesthetics(c("x", "y"), names(data), "position_quasirandom")

if (is.null(.$width)) .$width <- resolution(data$x, zero = FALSE) * 0.4
if (is.null(.$varwidth)) .$varwidth <- FALSE
Expand Down Expand Up @@ -64,6 +64,6 @@ if(requireNamespace("ggplot2",quietly=TRUE)&requireNamespace("proto",quietly=TRU

})
}else{
position_violinPoint <- function (width = NULL, varwidth = NULL, bandwidth=NULL)stop(simpleError("position_violinPoint requires ggplot2"))
position_quasirandom <- function (width = NULL, varwidth = NULL, bandwidth=NULL)stop(simpleError("position_quasirandom requires ggplot2"))
}

14 changes: 7 additions & 7 deletions man/position_violinPoint.Rd → man/position_quasirandom.Rd
@@ -1,10 +1,10 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/position-violinPoint.R
\name{position_violinPoint}
\alias{position_violinPoint}
% Please edit documentation in R/position-quasirandom.R
\name{position_quasirandom}
\alias{position_quasirandom}
\title{Violin point-style plots to show overlapping points. x must be discrete.}
\usage{
position_violinPoint(width = NULL, varwidth = NULL, bandwidth = NULL)
position_quasirandom(width = NULL, varwidth = NULL, bandwidth = NULL)
}
\arguments{
\item{width}{the maximum amount of spread (default: 0.4)}
Expand All @@ -19,14 +19,14 @@ Violin point-style plots to show overlapping points. x must be discrete.
}
\examples{
if(requireNamespace("ggplot2",quietly=TRUE)&requireNamespace("proto",quietly=TRUE)){
# ggplot2::qplot(class, hwy, data = ggplot2::mpg, position=position_violinPoint())
# ggplot2::qplot(class, hwy, data = ggplot2::mpg, position=position_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_violinPoint())
# ggplot2::qplot(variable, value, data = distro, position = position_violinPoint(width=0.1))
# ggplot2::qplot(variable, value, data = distro, position = position_quasirandom())
# ggplot2::qplot(variable, value, data = distro, position = position_quasirandom(width=0.1))
}
}

File renamed without changes.

0 comments on commit 75619d4

Please sign in to comment.