3

Say I have the following data that I want to plot:

x <- seq(.01, 1, .01)
plot(x)

Great. However, I want to change the scaling of the y-axis. I know that I can do

plot(x, log='y')

Is there an equivalent of this for exponential scaling?

(I know I could just plot(exp(x)) but this is part of a pretty complex plotting function that I am writing and I'd like to make this an optional parameter.)

Any help is greatly appreciated!

Florian
  • 579
  • 1
  • 10
  • 19
  • 1
    Not in a simple way, no. You could probably use `ggplot2`: see `?coord_trans`. (This is an unusual requirement: can you give a little more context?) – Ben Bolker Jan 23 '15 at 14:12
  • The context is that the variable on the y-axis has range [0, 1]. Most values are >.75, though, and therefore overlap quite a bit. I was hoping I could "stretch out" the upper range of the axis a bit to make the differences more pronounced. (Not to exaggerate my effect, but for added readability.) I'd have to do the same with another plot because they need to have the same y-axis values so that things can be compared easily between plots. – Florian Jan 23 '15 at 14:15
  • Anyways, if this isn't doable in a simple way, it's probably not worth it. It would just have been a cosmetic thing that would have been pretty neat. Thanks! – Florian Jan 23 '15 at 14:16
  • actually, for a [0,1] range the most common transformation would be logistic (which you can do using `coord_trans(y="qlogis")` following @alexforrence's example below ...) – Ben Bolker Jan 23 '15 at 22:47

1 Answers1

4

You can do this in ggplot2 using coord_trans:

library(scales)
library(ggplot2)

x <- seq(.01, 1, .01)
y <- seq(.01, 1, .01)
data <- data.frame(x, y)
qplot(x, y, data = data) + coord_trans(y = "exp")

enter image description here

alexforrence
  • 2,724
  • 2
  • 27
  • 30