ggLims: [!] Convenience functions to get and set the axis limits in...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/ggLims.R

Description

[!] Convenience functions to get and set the axis limits in ggplot2 object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ggLims(obj, axis = "y", ...)

## S3 method for class 'gg'
ggLims(obj, axis = "y", ...)

## S3 method for class 'numeric'
ggLims(obj, axis = "y", ...)

get_ggLims(obj, axis = "y", ...)

set_ggLims(obj, axis = "y", ..., expand = TRUE)

Arguments

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 or vector of 4 values (x min, x max, y min, y max) to be passed to function coord_cartesian. NOTE, that this function ggLims behaves differently than lims.

axis

(A string) either "x", "y" (default) or "xy" axis indicates axis if inerest.
In case of "set_ggLims" following inputs are also possible if a list should be returned: "xy_" or "xy_list".

...

For generic use.

expand

If TRUE, the default, adds a small expansion factor to the limits to ensure that data and axes don't overlap. If FALSE, limits are taken exactly from the data or xlim/ylim.

Details

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)

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

Author(s)

Vilmantas Gegzna

See Also

lims

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

Examples

 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)

GegznaV/spPlot documentation built on April 29, 2020, 11:06 p.m.