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
1 Comment » for Custom axis transformations in ggplot2
  1. Tsan-Kuang Lee says:

    Thank you for sharing this. I had to do the following instead:

    Perhaps there’s some version difference?

1 Pings/Trackbacks for "Custom axis transformations in ggplot2"
  1. […] scale using ggplot2 and the scales package in R for this purpose. Here I just mainly replicated this short post by Paul […]

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see