Learn R Programming

sjPlot (version 2.1.0)

adjust_plot_range: Adjust y range of ggplot-objects

Description

This method adjusts the y-range of a ggplot-object, which is useful when value labels are outside the plot region. A modified ggplot-object will be returned with adjusted y-range so everything should be visible. Note that this function only works on scale_y_continuous.

Usage

adjust_plot_range(gp, upper.mrgn = 1.05)

Arguments

gp
A ggplot-object. Usually, this will be returned by most of this package's plotting functions.
upper.mrgn
Defines the new margin of the upper y-bound of the plot. This value will be multiplied with gp's current total y-range. Default is 1.05, which means that the upper margin of the new plot's "visible" plot area will be increased by 5 percent. (i.e. the y-range is 105 percent of the original range, in order to make all object visible).

Value

The same ggplot-object, with adjusted y-range, so all graphics and labels should be visible.

References

OUseful.Info (2013)

Examples

Run this code
# sample data set
library(sjmisc)
data(efc)
# show frequencies of relationship-variable and
# retrieve plot object
gp <- sjp.frq(efc$e15relat, prnt.plot = FALSE)
# show current plot
plot(gp$plot)
# show adjusted plot
adjust_plot_range(gp$plot)

Run the code above in your browser using DataLab