Rescale a numeric vector or ggplot object, could be used for static
zoom-in in ggbio.
Usage
## S4 method for signature 'numeric'
rescale(x, to = c(0, 1),
from = range(x, na.rm = TRUE))
## S4 method for signature 'ggplot'
rescale(x, xlim, ylim, sx = 1, sy = 1)
## S4 method for signature 'gg'
rescale(x, xlim, ylim, sx = 1, sy = 1)
Arguments
x
A numeric object or ggplot object to be rescaled.
to
For numeric object. it's a vector of two numeric values, specifying
the range to be rescale.
from
Range of x.
xlim
For ggplot object. This specify the new limits on x-scale.
ylim
For ggplot object. This specify the new limits on y-scale.
sx
Scale fold for x-scale. Default is 1, no change.
sy
Scale fold for y-scale. Default is 1, no change.
Details
When x is numeric value, it's just call scales::rescale, please
refer to the manual page to check more details. If x is ggplot
object, it first try to estimate current x limits and y limits of the ggplot
object, then rescale based on those information.
Value
Return the object of the same class as x after rescaling.
Author(s)
Tengfei Yin
Examples
library(ggbio)
head(mtcars)
range(mtcars$mpg)
p <- qplot(data = mtcars, x = mpg, y = disp, geom = "point")
p.new <- rescale(p, xlim = c(20, 25))
p.new
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(ggbio)
Loading required package: BiocGenerics
Loading required package: parallel
Attaching package: 'BiocGenerics'
The following objects are masked from 'package:parallel':
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from 'package:stats':
IQR, mad, xtabs
The following objects are masked from 'package:base':
Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
rbind, rownames, sapply, setdiff, sort, table, tapply, union,
unique, unsplit
Loading required package: ggplot2
Need specific help about ggbio? try mailing
the maintainer or visit http://tengfei.github.com/ggbio/
Attaching package: 'ggbio'
The following objects are masked from 'package:ggplot2':
geom_bar, geom_rect, geom_segment, ggsave, stat_bin, stat_identity,
xlim
Warning message:
replacing previous import 'ggplot2::Position' by 'BiocGenerics::Position' when loading 'ggbio'
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/ggbio/rescale-method.Rd_%03d_medium.png", width=480, height=480)
> ### Name: rescale
> ### Title: rescale ggplot object
> ### Aliases: rescale rescale,numeric-method rescale,ggplot-method
> ### rescale,gg-method
>
> ### ** Examples
>
> library(ggbio)
> head(mtcars)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
> range(mtcars$mpg)
[1] 10.4 33.9
> p <- qplot(data = mtcars, x = mpg, y = disp, geom = "point")
> p.new <- rescale(p, xlim = c(20, 25))
> p.new
>
>
>
>
>
> dev.off()
null device
1
>