View source: R/np_categorical_plot_setup.R
makeLogTicks | R Documentation |
Generates the location and labels for the major tick marks for a given log base transformation along with optional minor tick mark location.
makeLogTicks(
dataRange,
minorCount = 10,
logScale = 2,
axisText = c(NULL, NULL),
expLabels = TRUE,
logAdjustment = 1
)
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 |
logAdjustment |
numeric; a number added to each value prior to log trasformation. Defaults value is 1. |
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.
a list with the following elements: major tick marks locations [[1]], major tick labels [[2]], minor tick mark locations [[3]].
axisTicks
, axis
, prepCategoryWindow
#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)}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.