Learn R Programming

fifer (version 1.1)

scaleBreak: Scatterplot with a Scale Break

Description

With skewed data, important relationships are often scaled so small because the graph attempts to capture the outliers. scaleBreak will plot two different scales on the same plot, shrinking the range where the outliers lay. The break in scale is indicated with a mark.

Usage

scaleBreak(x, y, axis = 2, breakpos = 1, plot.numbers = c(1, 2), ...)

Arguments

x
The x variables to be plotted.
y
The y variables to be plotted.
axis
Which axis should have two different scales. Currently, only implemented for "2," which is the y axis.
breakpos
At what point should the break occur? Defaults to 1.
plot.numbers
Which plots to include. Can be 1, 2, or c(1,2).
...
other arguments passed to plot

Examples

Run this code
# generate correlated data
d = data.frame(mvrnorm(1000, mu=c(0,0), Sigma=matrix(c(1,.6,.6,1), nrow=2)))
names(d) = c("x","y")
## Skew Y
d$y = d$y^2
scaleBreak(d$x, d$y, breakpos=4, plot.numbers=1)
## add a lowess line
lines(lowess(d$x, d$y), col="red")
## add a fitted line
mod = glm(y~x, data=d, family=inverse.gaussian)
curve(predict(mod,data.frame(x=x),type="resp"),add=TRUE,col="blue")
## add second plot
scaleBreak(d$x, d$y, breakpos=4, plot.numbers=2)

Run the code above in your browser using DataLab