Skip to content

Commit

Permalink
Added rescale_plot and NEWS
Browse files Browse the repository at this point in the history
  • Loading branch information
briandconnelly committed Oct 24, 2014
1 parent 7285eee commit 2d4a78d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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="[email protected]",
role=c("aut", "cre")))
Maintainer: Brian Connelly <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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

10 changes: 3 additions & 7 deletions R/rescale_golden.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) +
Expand All @@ -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))
}
9 changes: 2 additions & 7 deletions R/rescale_square.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion man/rescale_golden.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 2d4a78d

Please sign in to comment.