Customizing x-axis of graph

后端 未结 2 793
伪装坚强ぢ
伪装坚强ぢ 2021-01-23 13:53

I am using scale_x_discrete() to customize ticks and labels of x-axis.

However, as figure shows, the lines cut the right-side y-axis, which doesn\'t look g

相关标签:
2条回答
  • 2021-01-23 14:41

    There is also the "expand" argument from the ggplot website. Adjust the numbers to whatever look you are trying to achieve

    a + scale_x_discrete(breaks = c("2","4","8","16","32","64","128"),
                         labels=c("2","4","8","16","32","64","128"),
                         expand = c(.1,.1))
    
    0 讨论(0)
  • 2021-01-23 14:42

    Why are you using a discrete scale for something at appears to be continuous.

    If you replace scale_x_discrete with scale_x_continuous then this should work as you wish.

    b <- a + scale_x_continuous(breaks = 2^(1:7))
    b
    

    enter image description here You might be interested in a transformation to base 2, given the way your data for b appear only to be integer powers of 2.

    a + scale_x_continuous(breaks = 2^(1:7), trans = 'log2')
    

    enter image description here

    0 讨论(0)
提交回复
热议问题