diff --git a/DESCRIPTION b/DESCRIPTION index 788098f..216209d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: ggplot2bdc Type: Package Title: Themes and other functions for working with ggplot2 -Version: 0.1.4 -Date: 2014-09-17 +Version: 0.1.5 +Date: 2014-10-24 Authors@R: c(person(family="Connelly", given="Brian", email="bdc@bconnelly.net", role=c("aut", "cre"))) Maintainer: Brian Connelly diff --git a/NAMESPACE b/NAMESPACE index 6a545a9..66f8542 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,6 +7,7 @@ export(plate_labeller) export(ratio_golden) export(ratio_square) export(rescale_golden) +export(rescale_plot) export(rescale_square) export(span) export(theme_bdc_black) diff --git a/NEWS b/NEWS index 82ba7a7..17d71db 100644 --- a/NEWS +++ b/NEWS @@ -2,4 +2,5 @@ * Added rescale_plot function, which re-scales a plot to a given ratio * rescale_golden and rescale_square now call rescale_plot +* Created NEWS file diff --git a/R/rescale_golden.R b/R/rescale_golden.R index 708344f..2c52212 100644 --- a/R/rescale_golden.R +++ b/R/rescale_golden.R @@ -4,7 +4,7 @@ #' golden ratio (horizontally). #' #' @export -#' @param plot A ggplot2 plot object. By defauly, the last plot displayed is +#' @param plot A ggplot2 plot object. By default, the last plot displayed is #' used. #' @examples #' p <- ggplot(mtcars, aes(x=cyl, y=mpg)) + @@ -14,9 +14,5 @@ rescale_golden <- function(plot=last_plot()) { gr <- (1 + sqrt(5))/2 - built <- ggplot_build(plot) - xvals <- unique(unlist(lapply(built$data, function(l) l$x))) - yvals <- unique(unlist(lapply(built$data, function(l) l$y))) - - return(plot + coord_fixed(ratio=span(xvals)/span(yvals)/gr)) -} + return(rescale_plot(plot=plot, ratio=gr)) +} \ No newline at end of file diff --git a/R/rescale_square.R b/R/rescale_square.R index 7921439..a15711e 100644 --- a/R/rescale_square.R +++ b/R/rescale_square.R @@ -10,13 +10,8 @@ #' p <- ggplot(mtcars, aes(x=cyl, y=mpg)) + #' geom_point(shape=1) #' rescale_square() -#' + rescale_square <- function(plot=last_plot()) { - gr <- (1 + sqrt(5))/2 - built <- ggplot_build(plot) - xvals <- unique(unlist(lapply(built$data, function(l) l$x))) - yvals <- unique(unlist(lapply(built$data, function(l) l$y))) - - return(plot + coord_fixed(ratio=span(xvals)/span(yvals))) + return(rescale_plot(plot=plot, ratio=1)) } diff --git a/man/rescale_golden.Rd b/man/rescale_golden.Rd index 67dc888..0891e78 100644 --- a/man/rescale_golden.Rd +++ b/man/rescale_golden.Rd @@ -6,7 +6,7 @@ rescale_golden(plot = last_plot()) } \arguments{ -\item{plot}{A ggplot2 plot object. By defauly, the last plot displayed is +\item{plot}{A ggplot2 plot object. By default, the last plot displayed is used.} } \description{