Skip to content

Commit

Permalink
merged to 0.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
eclarke committed Dec 1, 2016
2 parents 6f257c5 + 4fa0a5a commit 7a87406
Show file tree
Hide file tree
Showing 28 changed files with 66 additions and 35 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: ggbeeswarm
Type: Package
Title: Categorical Scatter (Violin Point) Plots
Version: 0.5.2
Date: 2016-11-30
Version: 0.5.3
Date: 2016-12-01
Authors@R: c(
person(given="Erik", family="Clarke", role=c("aut", "cre"), email="erikclarke@gmail.com"),
person(given="Scott", family="Sherrill-Mix", role=c("aut"), email="sherrillmix@gmail.com"))
Expand Down
3 changes: 1 addition & 2 deletions R/geom-beeswarm.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ geom_beeswarm <- function(
mapping = NULL,
data = NULL,
priority = c("ascending", "descending", "density", "random", "none"),
cex=2,
cex=1,
groupOnX=NULL,
dodge.width=0,
stat='identity',
position = "quasirandom",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
Expand Down
29 changes: 27 additions & 2 deletions R/position-beeswarm.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' 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,dodge.width=0){
position_beeswarm <- function (priority = c("ascending", "descending", "density", "random", "none"),cex=1,groupOnX=NULL,dodge.width=0){
ggplot2::ggproto(NULL,PositionBeeswarm,priority = priority,cex=cex,groupOnX=NULL,dodge.width=dodge.width)
}

Expand Down Expand Up @@ -61,13 +61,38 @@ PositionBeeswarm <- ggplot2::ggproto("PositionBeeswarm",ggplot2:::Position, requ
trans_x<-NULL
trans_y<-NULL

getScaleDiff<-function(scales){
if(is.null(scales$limits))lims<-scales$range$range
else lims<-scales$limits
if(inherits(scales,'ScaleContinuous')){
limDiff<-diff(lims)
}else if(inherits(scales,'ScaleDiscrete')){
limDiff<-length(unique(lims))
}else{
stop('Unknown scale type')
}
if(limDiff==0)limDiff<-1
return(limDiff)
}

trans_xy <- function(xx){
xRange<-getScaleDiff(scales$x)
yRange<-getScaleDiff(scales$y)
newX<-ave(
data[,ifelse(params$groupOnX,'y','x')],
data[,ifelse(params$groupOnX,'x','y')],
FUN=function(yy){
if (length(yy) == 1) return(0)
else beeswarm::swarmx(0,yy,cex=params$cex,priority=params$priority)$x
else beeswarm::swarmx(
0,
yy,
cex=params$cex,
priority=params$priority,
#divisor is a magic number to get a reasonable baseline
#better option would be to figure out point size in user coords
xsize=ifelse(params$groupOnX,xRange,yRange)/100,
ysize=ifelse(params$groupOnX,yRange,xRange)/100
)$x
}
)
return(newX+xx)
Expand Down
9 changes: 5 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,17 @@ Using `geom_beeswarm`:
ggplot(iris,aes(Species, Sepal.Length)) + geom_beeswarm()
ggplot(mpg,aes(class, hwy)) + geom_beeswarm()
# With categorical y-axis
ggplot(mpg,aes(hwy, class)) + geom_beeswarm()
ggplot(mpg,aes(hwy, class)) + geom_beeswarm(cex=1.2)
# ggplot doesn't pass any information about the actual device size of the points
# to the underlying layout code, so it's important to manually adjust the `cex`
# parameter for best results
ggplot(mpg,aes(class, hwy)) + geom_beeswarm(cex=5)
ggplot(iris,aes(Species, Sepal.Length)) + geom_beeswarm(cex=4,priority='density')
# Also watch out for points escaping from the plot with geom_beeswarm
ggplot(mpg,aes(class, hwy)) + geom_beeswarm(cex=1.1)
ggplot(iris,aes(Species, Sepal.Length)) + geom_beeswarm(cex=1.2,priority='density')
# With automatic dodging
ggplot(sub_mpg, aes(class, displ, color=factor(cyl))) + geom_beeswarm(dodge.width=0.7, cex=4)
ggplot(sub_mpg, aes(class, displ, color=factor(cyl))) + geom_beeswarm(dodge.width=0.5)
```


Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ ggplot(mpg,aes(class, hwy)) + geom_beeswarm()

```r
# With categorical y-axis
ggplot(mpg,aes(hwy, class)) + geom_beeswarm()
ggplot(mpg,aes(hwy, class)) + geom_beeswarm(cex=1.2)
```

<img src="README_files/figure-html/ggplot2-beeswarm-3.png" title="plot of chunk ggplot2-beeswarm" alt="plot of chunk ggplot2-beeswarm" width="432" />
Expand All @@ -151,20 +151,21 @@ ggplot(mpg,aes(hwy, class)) + geom_beeswarm()
# ggplot doesn't pass any information about the actual device size of the points
# to the underlying layout code, so it's important to manually adjust the `cex`
# parameter for best results
ggplot(mpg,aes(class, hwy)) + geom_beeswarm(cex=5)
# Also watch out for points escaping from the plot with geom_beeswarm
ggplot(mpg,aes(class, hwy)) + geom_beeswarm(cex=1.1)
```

<img src="README_files/figure-html/ggplot2-beeswarm-4.png" title="plot of chunk ggplot2-beeswarm" alt="plot of chunk ggplot2-beeswarm" width="432" />

```r
ggplot(iris,aes(Species, Sepal.Length)) + geom_beeswarm(cex=4,priority='density')
ggplot(iris,aes(Species, Sepal.Length)) + geom_beeswarm(cex=1.2,priority='density')
```

<img src="README_files/figure-html/ggplot2-beeswarm-5.png" title="plot of chunk ggplot2-beeswarm" alt="plot of chunk ggplot2-beeswarm" width="432" />

```r
# With automatic dodging
ggplot(sub_mpg, aes(class, displ, color=factor(cyl))) + geom_beeswarm(dodge.width=0.7, cex=4)
ggplot(sub_mpg, aes(class, displ, color=factor(cyl))) + geom_beeswarm(dodge.width=0.5)
```

<img src="README_files/figure-html/ggplot2-beeswarm-6.png" title="plot of chunk ggplot2-beeswarm" alt="plot of chunk ggplot2-beeswarm" width="432" />
Expand Down
Binary file modified README_files/figure-html/ggplot2-beeswarm-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-beeswarm-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-beeswarm-3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-beeswarm-4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-beeswarm-5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-beeswarm-6.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-compare-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-compare-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-examples-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-examples-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-examples-3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-examples-4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-methods-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-methods-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-methods-3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-methods-4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-html/ggplot2-methods-5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 10 additions & 6 deletions inst/doc/usageExamples.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,29 @@ packageKeywords<-"visualization, display, one dimensional, grouped, groups, viol
###################################################
### code chunk number 14: dodgeBee (eval = FALSE)
###################################################
## ggplot(mapping=aes(labs,dat,color=labs2)) + geom_beeswarm(dodge.width=.8)
## ggplot(mapping=aes(labs,dat,color=labs2)) +
## geom_beeswarm(dodge.width=.8,cex=2)


###################################################
### code chunk number 15: showDodgeBee
###################################################
ggplot(mapping=aes(labs,dat,color=labs2)) + geom_beeswarm(dodge.width=.8)
ggplot(mapping=aes(labs,dat,color=labs2)) +
geom_beeswarm(dodge.width=.8,cex=2)


###################################################
### code chunk number 16: dodgeYBee (eval = FALSE)
###################################################
## ggplot(mapping=aes(dat,labs,color=labs2)) + geom_beeswarm(dodge.width=.8)
## ggplot(mapping=aes(dat,labs,color=labs2)) +
## geom_beeswarm(dodge.width=.8,cex=2)


###################################################
### code chunk number 17: showDodgeYBee
###################################################
ggplot(mapping=aes(dat,labs,color=labs2)) + geom_beeswarm(dodge.width=.8)
ggplot(mapping=aes(dat,labs,color=labs2)) +
geom_beeswarm(dodge.width=.8,cex=2)


###################################################
Expand Down Expand Up @@ -189,7 +193,7 @@ packageKeywords<-"visualization, display, one dimensional, grouped, groups, viol
## ggtitle('tukey') + labs(x='') +
## theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
## p6<-ggplot(mapping=aes(labs, dat)) +
## geom_beeswarm(alpha=.2,cex=8,size=.75) +
## geom_beeswarm(alpha=.2,size=.75) +
## ggtitle('geom_beeswarm') + labs(x='') +
## theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
## grid.arrange(p1, p2, p3, p4, p5, p6, ncol=3)
Expand Down Expand Up @@ -229,7 +233,7 @@ packageKeywords<-"visualization, display, one dimensional, grouped, groups, viol
ggtitle('tukey') + labs(x='') +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
p6<-ggplot(mapping=aes(labs, dat)) +
geom_beeswarm(alpha=.2,cex=8,size=.75) +
geom_beeswarm(alpha=.2,size=.75) +
ggtitle('geom_beeswarm') + labs(x='') +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
grid.arrange(p1, p2, p3, p4, p5, p6, ncol=3)
Expand Down
8 changes: 5 additions & 3 deletions inst/doc/usageExamples.Rnw
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ Or on the y-axis:

And with \code{geom_beeswarm}:
<<dodgeBee, echo=TRUE, eval=FALSE>>= labs2<-factor(rep(1:2,each=n))
ggplot(mapping=aes(labs,dat,color=labs2)) + geom_beeswarm(dodge.width=.8)
ggplot(mapping=aes(labs,dat,color=labs2)) +
geom_beeswarm(dodge.width=.8,cex=2)
@
\begin{center}
<<showDodgeBee, fig=TRUE, height=3.5, width=5, echo=FALSE>>=
<<dodgeBee>>
@
\end{center}
<<dodgeYBee, echo=TRUE, eval=FALSE>>=
ggplot(mapping=aes(dat,labs,color=labs2)) + geom_beeswarm(dodge.width=.8)
ggplot(mapping=aes(dat,labs,color=labs2)) +
geom_beeswarm(dodge.width=.8,cex=2)
@
\begin{center}
<<showDodgeYBee, fig=TRUE, height=3.5, width=5, echo=FALSE>>=
Expand Down Expand Up @@ -189,7 +191,7 @@ The first four options are included within \code{geom_quasirandom} using the \co
ggtitle('tukey') + labs(x='') +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
p6<-ggplot(mapping=aes(labs, dat)) +
geom_beeswarm(alpha=.2,cex=8,size=.75) +
geom_beeswarm(alpha=.2,size=.75) +
ggtitle('geom_beeswarm') + labs(x='') +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
grid.arrange(p1, p2, p3, p4, p5, p6, ncol=3)
Expand Down
Binary file modified inst/doc/usageExamples.pdf
Binary file not shown.
13 changes: 5 additions & 8 deletions man/geom_beeswarm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/position_beeswarm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions vignettes/usageExamples.Rnw
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ Or on the y-axis:

And with \code{geom_beeswarm}:
<<dodgeBee, echo=TRUE, eval=FALSE>>= labs2<-factor(rep(1:2,each=n))
ggplot(mapping=aes(labs,dat,color=labs2)) + geom_beeswarm(dodge.width=.8)
ggplot(mapping=aes(labs,dat,color=labs2)) +
geom_beeswarm(dodge.width=.8,cex=2)
@
\begin{center}
<<showDodgeBee, fig=TRUE, height=3.5, width=5, echo=FALSE>>=
<<dodgeBee>>
@
\end{center}
<<dodgeYBee, echo=TRUE, eval=FALSE>>=
ggplot(mapping=aes(dat,labs,color=labs2)) + geom_beeswarm(dodge.width=.8)
ggplot(mapping=aes(dat,labs,color=labs2)) +
geom_beeswarm(dodge.width=.8,cex=2)
@
\begin{center}
<<showDodgeYBee, fig=TRUE, height=3.5, width=5, echo=FALSE>>=
Expand Down Expand Up @@ -189,7 +191,7 @@ The first four options are included within \code{geom_quasirandom} using the \co
ggtitle('tukey') + labs(x='') +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
p6<-ggplot(mapping=aes(labs, dat)) +
geom_beeswarm(alpha=.2,cex=8,size=.75) +
geom_beeswarm(alpha=.2,size=.75) +
ggtitle('geom_beeswarm') + labs(x='') +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
grid.arrange(p1, p2, p3, p4, p5, p6, ncol=3)
Expand Down

0 comments on commit 7a87406

Please sign in to comment.