Skip to content

Commit

Permalink
Merge pull request #1 from stefanedwards/facets
Browse files Browse the repository at this point in the history
Incorporate Facets into master.
  • Loading branch information
stefanedwards authored Apr 28, 2017
2 parents a891059 + 76dd8c2 commit 8f915d0
Show file tree
Hide file tree
Showing 37 changed files with 634 additions and 477 deletions.
4 changes: 3 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
^.*\.Rproj$
^\.Rproj\.user$
^/lib/$
^lib\$
.Rprofile
^README\.Rmd$
^README\*.png$
^README\*.png$
^lib$
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

inst/doc

/lib/
/lib/
/README/cache/
31 changes: 17 additions & 14 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
Package: splot
Type: Package
Title: splot - Stefan's plotting package
Title: splot! - Stefan's plot library of tricks
URL: https://github.com/stefanedwards/splot
BugReports: https://github.com/stefanedwards/splot/issues
Version: 0.2.0
Author: Stefan McKinnon Edwards <sme@iysik.com>
Author@R: person(c('Stefan','McKinnon'), 'Edwards', email='sme@iysik.com',
role=c('aut','ctb','cre'))
Author: Stefan McKinnon Edwards <sme@iysik.com> [aut, ctb, cre]
Maintainer: Stefan McKinnon Edwards <sme@iysik.com>
Description: Yet another ggplot2 and knitr extension package.
Imports:
ggplot2,
grid,
gridExtra,
gtable,
RCurl
Includes functions for manipulating ggplot2 legends,
axis lines, and a bit of knitr magic.
Depends:
ggplot2,
R (>= 3.1.0)
Imports:
ggplot2 (>= 2.2.0),
grid,
gridExtra,
gtable,
Enhances: ggplot2,
knitr
License: GPL-3
RCurl,
knitr (>= 1.12)
License: GPL-3 + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 5.0.1
Expand All @@ -28,10 +30,11 @@ Collate:
'coord-capped.r'
'coord-flex.r'
'facet-rep-lab.r'
'facet-wrap.r'
'knit_print.r'
'legends.r'
'splot.r'
Suggests:
knitr,
rmarkdown
rmarkdown,
stringr
VignetteBuilder: knitr
12 changes: 0 additions & 12 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,5 @@ import(grid)
import(gridExtra)
import(gtable)
import(knitr)
importFrom(ggplot2,CoordCartesian)
importFrom(ggplot2,CoordFixed)
importFrom(ggplot2,CoordFlip)
importFrom(ggplot2,FacetGrid)
importFrom(ggplot2,FacetWrap)
importFrom(ggplot2,ggproto)
importFrom(grid,unit)
importFrom(gtable,gtable_add_cols)
importFrom(gtable,gtable_add_grob)
importFrom(gtable,gtable_add_rows)
importFrom(gtable,gtable_col)
importFrom(gtable,gtable_height)
importFrom(gtable,gtable_row)
importFrom(gtable,gtable_width)
20 changes: 11 additions & 9 deletions R/brackets.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ NULL
#' If \code{waiver()} (default), use \code{axis.ticks.length} from \code{\link{theme}}.
#'
#' @examples
#' library(ggplot2)
#' p <- ggplot(mpg, aes(as.factor(cyl), hwy, colour=class)) +
#' geom_point(position=position_jitter(width=0.3)) +
#' theme_bw() +
Expand All @@ -39,7 +40,8 @@ NULL
#' # A further adjustment,
#' p + theme(panel.grid.major.x = element_blank())
#' @import grid
#' @importFrom gtable gtable_col gtable_row gtable_width gtable_height
#' @import ggplot2
#' @import gtable
brackets_horisontal <- function(direction = c('up','down'),
length = unit(0.05, 'native'),
tick.length = waiver()) {
Expand Down Expand Up @@ -71,12 +73,12 @@ brackets_horisontal <- function(direction = c('up','down'),
labels <- agrob$children[[ind.notline]]$grobs[[ind.text]]

gt <- switch(position,
top = gtable_col('axis',
top = gtable::gtable_col('axis',
grobs = list(labels, brackets),
width = unit(1, 'npc'),
heights = unit.c(grobHeight(labels), tick.length)
),
bottom = gtable_col('axis',
bottom = gtable::gtable_col('axis',
grobs = list(brackets, labels),
width = unit(1, 'npc'),
heights = unit.c(tick.length, grobHeight(labels))
Expand All @@ -89,8 +91,8 @@ brackets_horisontal <- function(direction = c('up','down'),

ggplot2:::absoluteGrob(
gList(gt),
width = gtable_width(gt),
height = gtable_height(gt),
width = gtable::gtable_width(gt),
height = gtable::gtable_height(gt),
vp = justvp
)
}
Expand Down Expand Up @@ -132,12 +134,12 @@ brackets_vertical <- function(direction = c('left','right'),
labels <- agrob$children[[ind.notline]]$grobs[[ind.text]]

gt <- switch(position,
left = gtable_row('axis',
left = gtable::gtable_row('axis',
grobs = list(labels, brackets),
height = unit(1, 'npc'),
widths = unit.c(grobWidth(labels), tick.length)
),
right = gtable_row('axis',
right = gtable::gtable_row('axis',
grobs = list(brackets, labels),
height = unit(1, 'npc'),
widths = unit.c(tick.length, grobWidth(labels))
Expand All @@ -150,8 +152,8 @@ brackets_vertical <- function(direction = c('left','right'),

ggplot2:::absoluteGrob(
gList(gt),
width = gtable_width(gt),
height = gtable_height(gt),
width = gtable::gtable_width(gt),
height = gtable::gtable_height(gt),
vp = justvp
)
}
Expand Down
1 change: 1 addition & 0 deletions R/coord-capped.r
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ NULL
#' @rdname coord_capped
#' @export
#' @examples
#' library(ggplot2)
#' # Notice how the axis lines of the following plot meet in the lower-left corner.
#' p <- ggplot(mtcars, aes(x = mpg)) + geom_dotplot() +
#' theme_bw() +
Expand Down
20 changes: 12 additions & 8 deletions R/coord-flex.r
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ NULL
#' limits are taken exactly from the data or \code{xlim}/\code{ylim}.
#' @export
#' @examples
#'
#' library(ggplot2)
#' # A standard plot
#' p <- ggplot(mtcars, aes(disp, wt)) +
#' geom_point() +
Expand All @@ -66,7 +66,8 @@ NULL
#'
#' # Also works with secondary axes:
#' p + scale_y_continuous(sec.axis=sec_axis(~5*., name='wt times 5')) +
#' coord_flex_cart(left=brackets_vertical(), bottom=capped_horisontal('right'), right=capped_vertical('both', gap=0.02))
#' coord_flex_cart(left=brackets_vertical(), bottom=capped_horisontal('right'),
#' right=capped_vertical('both', gap=0.02))
#'
#'
#' # Supports the usual 'coord_fixed':
Expand Down Expand Up @@ -165,32 +166,35 @@ flex_render_axis_v <- function(self, scale_details, theme) {

# ggproto objects -------------------------------------------------------------

#' @rdname ggplot2-ggproto
#' @rdname splot-ggproto
#' @keywords internal
#' @format NULL
#' @usage NULL
#' @export
#' @importFrom ggplot2 CoordCartesian ggproto
#' @import ggplot2
CoordFlexCartesian <- ggplot2::ggproto('CoordFlexCartesian',
`_inherit` = ggplot2::CoordCartesian,
render_axis_h = flex_render_axis_h,
render_axis_v = flex_render_axis_v
)

#' @rdname ggplot2-ggproto
#' @rdname splot-ggproto
#' @keywords internal
#' @format NULL
#' @usage NULL
#' @export
#' @importFrom ggplot2 CoordFlip ggproto
#' @import ggplot2
CoordFlexFlipped <- ggplot2::ggproto('CoordFlexFlipped', `_inherit` = ggplot2::CoordFlip,
render_axis_h = flex_render_axis_h,
render_axis_v = flex_render_axis_v
)

#' @rdname ggplot2-ggproto
#' @rdname splot-ggproto
#' @keywords internal
#' @format NULL
#' @usage NULL
#' @export
#' @importFrom ggplot2 CoordFixed ggproto
#' @import ggplot2
CoordFlexFixed <- ggplot2::ggproto('CoordFlexFlipped', `_inherit` = ggplot2::CoordFixed,
render_axis_h = flex_render_axis_h,
render_axis_v = flex_render_axis_v
Expand Down
Loading

0 comments on commit 8f915d0

Please sign in to comment.