Home > Enterprise >  R ggplot scale_y_log10, remove 10^(-0.5) from log scale
R ggplot scale_y_log10, remove 10^(-0.5) from log scale

Time:05-29

I'm using the following code to get a log scale on my axis, however, it also displays intermediate values like 10^(0.5), 10^(1.5), 10^(2.5)... How can I get rid of those and only show the full 10^1, 10^2,..., as my axis labels?

scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
            labels = trans_format("log10", math_format(10^.x))) 

Thank you for your help!

CodePudding user response:

You could try playing with the n argument to scales::breaks_log (the default is n=5), as in

scale_y_log10(breaks = breaks_log(n=3))

Or if you are willing to hard-code the solution for a particular graph you could use

scale_y_log10(breaks = 10^(1:3))

once you've established the range you want.

  • Related