Search code examples
rggplot2scale

Scaling axis with different decimal places in ggplot


I am scaling x axis with following code.

 > scale_x_continuous("", limits = c(0.1, 10), breaks = c( .1, .2, .4,.67, .8, 1, 1.25, 1.5, 2.5, 5, 10))

But in the plot, numbers overlaps with one another (see the pic: points 0.67 to 1.25). To avoid this overlap, I want the control decimal for points 0.67 to 1.25. I want to keep,2 decimals from .67 and 1.25, one decimal places for .8 and no decimal for 1.

Basically, I want to show the numbers like this: .1,.2,.4,.67,.8,1,1.25,1.5,2.5,5,10. How can I do that?

enter image description here


Solution

  • Just set the labels= as well. You can put whatever value you want there.

    scale_x_continuous("", 
      limits = c(0.1, 10), 
      breaks = c( .1, .2, .4,.67, .8, 1, 1.25, 1.5, 2.5, 5, 10),
      labels = c( ".1", ".2", ".4" , ".67", ".8", "1", "1.25", "1.5", "2.5", "5", "10"),
    )