2
votes

I want to apply different length of ticks in one ggplot graph, like this: enter image description here

I tried to use

scale_x_continuous(breaks = c(seq(0,1, by = 0.1),seq(1,5,1)))

to customize the ticks but this only gives different step sizes. Any suggestions? enter image description here

Sorry the images are attached as links.

1
Please provide reproducible data and codeacylam

1 Answers

0
votes

What you are observing is the effect of a logged x scale.

library(dplyr)
library(ggplot2)
library(readr)

"x,y
0.09838589987314314, 431.84212280818747
0.19646546437091444, 1072.2954863657576
0.29750771557320366, 1347.2844856323754
0.3955242765781446, 1546.716447763184
0.49672163253953483, 1501.5827721848123
0.5940891079858363, 1320.5680378691911
0.6990737071572558, 1178.7879191946129
0.7962694810692876, 1061.1374091606106
0.8923393306748771, 919.3252883525568
0.9838589987314309, 831.8421228081871
1.1025615087338325, 744.3696246416428
1.1863284538600922, 678.0025335022334
1.286887658830817, 599.5653043536236
1.3959707710478373, 554.3356223748249
1.4898579966508398, 509.09527301820117
1.6030497343115249, 454.80365357690516
1.6696092455367386, 403.50956730448706
1.7674609336378837, 376.37709180612046
1.886333052497789, 346.2310820721382
1.9968863894545188, 322.11747449829977
2.079798216336457, 291.9554636975797
2.31183906016707, 255.79838655910407
2.5078022414885948, 213.5875725048336
2.6764666574617317, 192.49816654443634
2.9033375196831206, 162.36282418827932
3.0238856986296256, 153.3328888592573
3.149439104611845, 144.3029535302353
3.3340199781197377, 132.26481765451013
3.500818628686328, 117.20248016534447
3.6759620972244393, 111.19674644976362
3.7975657368770896, 99.14260950730068
3.923192118001404, 96.14507633842254
4.086085223703413, 96.17174478298557
4.616479953856948, 78.13854256950458
5.089953102964006, 63.10820721381424
5.61198637258845, 57.13447563170894
6.038356194859665, 51.14474298286564
6.712049082852011, 42.15747716514443
6.990737071572554, 33.12754183612242
7.521857271241964, 36.194412960864156
8.093329248357565, 27.185812387492433
8.226106849449925, 27.19647976531769
8.498232760057107, 27.217814520968204
8.85108408255861, 24.22561504100281
9.446371423329051, 24.268284552303612" %>% 
  read_csv() %>% 
  ggplot(aes(x, y)) + 
  geom_point() + 
  geom_line() + 
  scale_y_continuous(breaks = seq(0, 1600, 200)) + 
  labs(x = "Window mm", 
       y = element_blank()) -> p

p

Produces this:

no log plot

But if we log the x scale:

p + 
  scale_x_log10(breaks = c(seq(0.1, 0.3, 0.1), seq(0.4, 0.8, 0.2), 1:10), 
                labels = c(seq(0.1, 0.3, 0.1), seq(0.4, 0.8, 0.2), 1:10))

We get this:

logged plot

Now you will have to apply this to your data.