0

I am trying to make a 2D plot in which both axis are log scaled. In my case, I am working with these data frame:

my_data = data.frame(oX = c(90, 95, 97.5, 99, 99.5, 99.75, 99.9), 
                    obs.P1 = c(10.02099, 5.01323, 2.50981, 1.00575, 0.50388, 0.25591, 0.10194))

And the "raw" (not scaled) plot looks somehow like this:

plot without axis scaling

To plot using ggplot, I run the following:

ggplot(my_data, aes(x = oX, y = obs.P1)) +
  geom_line(aes(y = obs.P1), color='midnightblue', size = 1) + 
  geom_point(aes(y = obs.P1), color='midnightblue', size = 2.5) +
  scale_x_continuous(trans = 'log10') + scale_y_continuous(trans = 'log10')

and I get the following figure:

ggplot2 with failed axis scaling

Using R graphics I get similar results. The script is this one:

plot(my_data$oX, my_data$obs.P1, log = 'xy')

And the figure:

R basics plot with failed axis scaling

The problem is that when I try to scale both axis, I cannot see any changes in the x-axis (whilst the y-axis is log-scaled compared to the original plot, the x-axis remains in linear scale). Any idea about what am I doing wrong?

benson23
  • 16,369
  • 9
  • 19
  • 38
guigufe
  • 1
  • 1
  • Your question is unclear. What do you mean you don't see any changes? you just showed that both plots does the thing you expect. – Mossa May 03 '22 at 13:19
  • 2
    I think this is just an artifact - in this small range it appears almost linear. type `diff(log10(c(90,92.5,95,97.5,100)))` - and see how little the difference changes, the first and last differ only by about 10%, and it looks to be the case in your plot. Or plot with `x = oX-89` - then you clearly see the logarithmic axis – bdecaf May 03 '22 at 13:56

0 Answers0