plot_logscale: Add log transformations to graphs

View source: R/plot_logscales.R

plot_logscaleR Documentation

Add log transformations to graphs

Description

This function allows "log10" or "log2" transformation of X or Y axes. With "log10" transformation, log10 ticks are also added on the outside.

Usage

plot_logscale(
  Plot,
  LogYTrans = "log10",
  LogXTrans,
  LogYBreaks = waiver(),
  LogXBreaks = waiver(),
  LogYLimits = NULL,
  LogXLimits = NULL,
  LogYLabels = waiver(),
  LogXLabels = waiver(),
  fontsize = 22,
  ...
)

Arguments

Plot

a ggplot2 object.

LogYTrans

transform Y axis into "log10" (default) or "log2"

LogXTrans

transform X axis into "log10" or "log2"

LogYBreaks

argument for ggplot2[scale_y_continuous] for Y axis breaks on log scales, default is waiver(), or provide a vector of desired breaks.

LogXBreaks

argument for ggplot2[scale_x_continuous] for Y axis breaks on log scales, default is waiver(), or provide a vector of desired breaks.

LogYLimits

a vector of length two specifying the range (minimum and maximum) of the Y axis.

LogXLimits

a vector of length two specifying the range (minimum and maximum) of the X axis.

LogYLabels

argument for ggplot2[scale_y_continuous] for Y axis labels on log scales, default is waiver(), or provide a vector of desired labels.

LogXLabels

argument for ggplot2[scale_x_continuous] for Y axis labels on log scales, default is waiver(), or provide a vector of desired labels.

fontsize

this parameter sets the linewidth of the log10 tickmarks (8*fontsize/22 for long ticks and 4*fontsize/22 for middle ticks). It is set to 20 as default to be consistent with rest of grafify. It will need to be changed to 12, which is the default fontsize for graphs produced natively with ggplot2.

...

any other arguments to pass to scale_y_continuous[ggplot2] or scale_x_continuous[ggplot2]

Details

Arguments allow for axes limits, breaks and labels to passed on.

Value

This function returns a ggplot2 object of class "gg" and "ggplot".

Examples

#save a ggplot object
P <- ggplot(data_t_pratio, 
aes(Genotype,Cytokine))+
geom_jitter(shape = 21, 
size = 5, width = .2, 
aes(fill = Genotype), 
alpha = .7)
#transform Y axis
plot_logscale(Plot = P)

#or in one go 
plot_logscale(ggplot(data_t_pratio, 
aes(Genotype,Cytokine))+
geom_jitter(shape = 21, 
size = 5, width = .2, 
aes(fill = Genotype), 
alpha = .7))


grafify documentation built on May 29, 2024, 3:49 a.m.