Description Usage Arguments Details Value Author(s) See Also Examples
[!] Convenience functions to get and set the axis limits in ggplot2 object
1 2 3 4 5 6 7 8 9 10 11 |
obj |
Eithar a ggplot object (for getting the limits) or a numeric
vector with limits (for setting the limits).
If values of limits: either vector of 2 values (min and max)
for axis indicated in |
axis |
(A string) either "x", "y" (default) or "xy" axis
indicates axis if inerest. |
... |
For generic use. |
expand |
If |
get_ggLims(obj, "y")
is a wrapper for
ggplot_build(obj)$panel$ranges[[1]]$y.range
set_ggLims(value, "y")
is a wrapper for
coord_cartesian(ylim = value)
One of the following depending on inputs:
a) vector of ranges of one axis as
(min, max)
, or both axes as
(x_min, x_max, y_min, y_max)
,
b) list of limits for both axes as
list(x = (x_min, x_max), y = (y_min, y_max)
c) updated ggplot object
Vilmantas Gegzna
Other spPlot functions for spectroscopy and hyperSpec:
facet_wl()
,
gg_palette()
,
ggplot.hyperSpec()
,
label_expr2text()
Other spPlot functions for ggplot2:
facet_wl()
,
gg_palette()
,
ggplot.hyperSpec()
,
nTick
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | library(ggplot2)
library(spPlot)
obj <- qplot(mpg, wt, data = mtcars, geom = c("line","point"))
# Get y axis limits ==========================
get_ggLims(obj)
ggLims(obj)
ggLims(obj, "y")
ggLims(obj, "x")
ggLims(obj, "xy") # return as a vector
ggLims(obj, "xy_") # return as a list
## Not run:
# Set y .axis limits ==========================
# Original plot:
obj
# Settim limmits this way:
obj + ggLims(c(0, 5))
# is the same as doing it this way:
obj + ggLims(c(0, 5),"y")
# and this way:
obj + coord_cartesian(ylim = c(0, 5))
# BUT differs from this way, where some lines are trimmed:
obj + ylim(c(0, 5))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.