makeLogTicks: format a log scale axis

View source: R/np_categorical_plot_setup.R

makeLogTicksR Documentation

format a log scale axis

Description

Generates the location and labels for the major tick marks for a given log base transformation along with optional minor tick mark location.

Usage

makeLogTicks(
  dataRange,
  minorCount = 10,
  logScale = 2,
  axisText = c(NULL, NULL),
  expLabels = TRUE,
  logAdjustment = 1
)

Arguments

dataRange

numeric; a numeric vector with the min and max values for the data set prior to log transformation.

minorCount

positive integer; the number of minor tick marks to be drawn between each major tick.

logScale

numeric; the logarithm base to use for the log scale transformation.

axisText

character; a length two character vector containing text to be prepend or append to the major tick labels, respectively.

expLabels

logical; if set to TRUE, the major labels will written as logbase^{x}. Otherwise the labels will correspond to the non-transformed values at that point.

logAdjustment

numeric; a number added to each value prior to log trasformation. Defaults value is 1.

Details

Base R does not have great visual queues to indicate when data is being plotted in log scale. This is a simple function takes the min and max of the untransformed data and uses axisTicks from base R to determine the location of the major tick marks in the new scale. To better indicate that the graph is on a log scale, the major tick-marks are labeled in the untransformed values or expressed in as logScale^{x} when expLabels=TRUE. The minor tick marks are drawn equidistant from each other between the major tick marks in the untransformed scale giving them shrinking appearance when rendered in log scale coordinates. This can help helps with the interpretation of data within the log scale and adds another visual indication that the data has been transformed. The value of minorCount gives number of minor ticks to be drawn between each pair of major tick-marks. axisText allows for symbols or units such as ' It is worth stressing again that the input values to dataRange are assumed to be raw values prior to log transformation. If log transformed values are given, the axis will be drawn correctly.

Value

a list with the following elements: major tick marks locations [[1]], major tick labels [[2]], minor tick mark locations [[3]].

See Also

axisTicks, axis, prepCategoryWindow

Examples

#plot(1:10,log(1:10,2),yaxt="n",ylab="")
#\donttest{majorTicks<-makeLogTicks(c(0,10),minorCount= 4,logScale=2,
#   axisText=c("","mg"), expLabels=TRUE)}
#\donttest{axis(side=2,lab=majorTicks[[2]],at=majorTicks[[1]],las=2)}
#\donttest{axis(side = 2, at = majorTicks[[3]], labels = FALSE, tcl = -0.2)}

ZachHunter/NicePlots.R documentation built on Sept. 23, 2023, 4:04 a.m.