Custom axis transformations in ggplot2

To apply a data transformation on an axis in a ggplot, you can use coordinate transformations. For more detail see the ggplot2 documentation. A number of coordinate transformations is available, including log10 and sqrt. However, if you want to perform a custom transformation this is not trivial. Say the transformation involves x = 1/x. To get this transformation available you can define the following function (see ?trans_new for more details):

from now one you can use one_over as a coordinate transform. Note that the name convention is nameoftrans_trans. Example code:

Tagged with: ,
Posted in R stuff

Leave a Reply