-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate new coords into rect for gggda & scaffold for ggbiplot
- Loading branch information
1 parent
6073c36
commit f80e03c
Showing
11 changed files
with
158 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#' @title Convenience coordinate system for scaffolding axes | ||
#' | ||
#' @description 2- (and 3-) dimensional biplots require that coordinates lie on | ||
#' the same scale but may additionally benefit from a square plotting window. | ||
#' While `CoordRect` provides control of coordinate and window aspect ratios, | ||
#' the convenience `CoordScaffold` system also fixes the coordinate aspect | ||
#' ratio at `1` and gives the user control only of the plotting window. | ||
#' | ||
#' @inheritParams ggplot2::coord_fixed | ||
#' @param window_ratio aspect ratio of plotting window | ||
#' @example inst/examples/ex-coord-scaffold.r | ||
#' @export | ||
coord_scaffold <- function( | ||
window_ratio = 1, | ||
xlim = NULL, ylim = NULL, expand = TRUE, clip = "on" | ||
) { | ||
ggplot2:::check_coord_limits(xlim) | ||
ggplot2:::check_coord_limits(ylim) | ||
ggproto( | ||
NULL, CoordScaffold, | ||
limits = list(x = xlim, y = ylim), | ||
window_ratio = window_ratio, | ||
expand = expand, | ||
clip = clip | ||
) | ||
} | ||
|
||
#' @rdname ordr-ggproto | ||
#' @format NULL | ||
#' @usage NULL | ||
#' @export | ||
CoordScaffold <- ggproto( | ||
"CoordScaffold", CoordRect, | ||
|
||
# require coordinate aspect ratio to be 1 | ||
aspect = function(self, ranges) { | ||
diff(ranges$y.range) / diff(ranges$x.range) | ||
} | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# ensures that the resolutions of the axes and the dimensions of the plotting | ||
# window respect the specified aspect ratios | ||
p <- ggplot(mtcars, aes(mpg, hp/10)) + geom_point() | ||
p + coord_rect(ratio = 1) | ||
p + coord_rect(ratio = 1, window_ratio = 2) | ||
p + coord_rect(ratio = 1, window_ratio = 1/2) | ||
p + coord_rect(ratio = 5) | ||
p + coord_rect(ratio = 1/5) | ||
p + coord_rect(xlim = c(15, 30)) | ||
p + coord_rect(ylim = c(15, 30)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# resize the plot to see that the specified aspect ratio is maintained | ||
p <- ggplot(mtcars, aes(mpg, hp/10)) + geom_point() | ||
p + coord_scaffold() | ||
p + coord_scaffold(window_ratio = 2) | ||
|
||
# prevent rescaling in response to `theme()` aspect ratio | ||
p <- ggplot(mtcars, aes(mpg, hp/5)) + geom_point() | ||
p + coord_equal() + theme(aspect.ratio = 1) | ||
p + coord_scaffold() + theme(aspect.ratio = 1) | ||
|
||
# NB: `theme(aspect.ratio = )` overrides `Coord*$aspect`: | ||
p + coord_fixed(ratio = 1) + theme(aspect.ratio = 1) | ||
p + coord_scaffold(window_ratio = 2) + theme(aspect.ratio = 1) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.