rggplot2

Irregular tick-lines when I add extra tick


Below is my ggplot

library(ggplot2)

dat = structure(list(x = c(0.038362636053748, 0.0350340127781965, 0.0170342545048334, 
0.0456167190917768, 0.0246753886074293, 0.015978419353487, 0.02345346731483, 
0.035775313929189, 0.0362819382816087, 0.0460074759379495, 0.0355744209617842, 
0.0278667781117838, 0.0421519015298691, 0.0305214132531546, 0.0204445846693125, 
0.0358961151842959, 0.0457219827605877, 0.0376390527805779, 0.0338345712644514, 
0.0251005005848128, 0.0472049922449514, 0.0303733868291602, 0.0189651491877157, 
0.0413547690375708, 0.0273687251936644, 0.0229116637981497, 0.01601815621485, 
0.0462230957380962, 0.0341604682744946, 0.0283300181594677, 0.0451373701705597, 
0.0258701920940075, 0.0484355257067364, 0.0219022567092907, 0.0367744490783662, 
0.01956381403259, 0.0354586373071652, 0.018800362132024, 0.0348129489354324, 
0.0423994669434615, 0.0377335927507374, 0.0238844661298208, 0.035316273967037, 
0.0324556400394067, 0.0411237295146566, 0.0484172792441677, 0.0420868713012897, 
0.0158112288371194, 0.0189540091762319, 0.0224225894582924, 0.0443572197458707, 
0.033456686232239, 0.0189867398678325, 0.0209547734842636, 0.0416194785234984, 
0.0280921992170624, 0.0410054941219278, 0.0280553078558296, 0.0264267705800012, 
0.0297777217288967, 0.0254321554536, 0.0274427520309109, 0.0431906649225857, 
0.0332097801065538, 0.0338664089515805, 0.0299551230377983, 0.0431238019827288, 
0.0456232655630447, 0.033413805536693, 0.0321371672407258, 0.0303111031767912, 
0.0489989949064329, 0.0481856980791781, 0.0168232739227824, 0.0351056582189631, 
0.0468146548746154, 0.0338977668609004, 0.038348187035881, 0.0214134330151137, 
0.0412089407735039, 0.0487178196012974, 0.0486091111518908, 0.0240328466054052, 
0.0393267812766135, 0.0275843715528026, 0.0270194761327002, 0.042719343539793, 
0.0311470661952626, 0.0385598440270405, 0.0298005522810854, 0.048948519427795, 
0.0287848878221121, 0.0329418209090363, 0.0232495477492921, 0.0420155188802164, 
0.0266449011012446, 0.0486524973902851, 0.0270629280386493, 0.0351066672045272, 
0.0234074234869331, 0.0286317409807816), y = c(0.674042553191489, 
0.668936170212766, 0.662127659574468, 0.672340425531915, 0.663829787234043, 
0.662127659574468, 0.660425531914894, 0.67063829787234, 0.67063829787234, 
0.67063829787234, 0.668936170212766, 0.667234042553192, 0.672340425531915, 
0.665531914893617, 0.660425531914894, 0.67063829787234, 0.672340425531915, 
0.672340425531915, 0.667234042553192, 0.663829787234043, 0.67063829787234, 
0.665531914893617, 0.663829787234043, 0.672340425531915, 0.667234042553192, 
0.662127659574468, 0.662127659574468, 0.67063829787234, 0.667234042553192, 
0.668936170212766, 0.672340425531915, 0.665531914893617, 0.67063829787234, 
0.662127659574468, 0.67063829787234, 0.662127659574468, 0.668936170212766, 
0.663829787234043, 0.668936170212766, 0.672340425531915, 0.672340425531915, 
0.660425531914894, 0.668936170212766, 0.665531914893617, 0.672340425531915, 
0.67063829787234, 0.672340425531915, 0.662127659574468, 0.663829787234043, 
0.662127659574468, 0.672340425531915, 0.667234042553192, 0.663829787234043, 
0.660425531914894, 0.672340425531915, 0.668936170212766, 0.672340425531915, 
0.668936170212766, 0.665531914893617, 0.667234042553192, 0.663829787234043, 
0.667234042553192, 0.672340425531915, 0.667234042553192, 0.667234042553192, 
0.667234042553192, 0.672340425531915, 0.672340425531915, 0.667234042553192, 
0.665531914893617, 0.665531914893617, 0.672340425531915, 0.67063829787234, 
0.662127659574468, 0.668936170212766, 0.672340425531915, 0.667234042553192, 
0.674042553191489, 0.662127659574468, 0.672340425531915, 0.67063829787234, 
0.67063829787234, 0.660425531914894, 0.674042553191489, 0.667234042553192, 
0.667234042553192, 0.672340425531915, 0.665531914893617, 0.674042553191489, 
0.667234042553192, 0.672340425531915, 0.668936170212766, 0.665531914893617, 
0.662127659574468, 0.672340425531915, 0.665531914893617, 0.67063829787234, 
0.667234042553192, 0.668936170212766, 0.660425531914894, 0.668936170212766
)), class = "data.frame", row.names = c(NA, -101L))

ggplot(dat, aes(x, y)) +
  geom_point() +
  scale_x_continuous(limit = c(1.5/100, 7/100), breaks = c(0.037, seq(1.5/100, 7/100, by = .5/100)))

As can be seen the x-axis tick-lines become pretty irregular when I extra tick item at 0.037.

Is there any way to put tick-lines at regular interval still having an extra tick line at 0.037?


Solution

  • You can explicitly set the positions for the minor breaks and grid lines using the minor_breaks= argument:

    library(ggplot2)
    
    ggplot(dat, aes(x, y)) +
      geom_point() +
      scale_x_continuous(
        limit = c(1.5 / 100, 7 / 100),
        breaks = c(0.037, seq(1.5 / 100, 7 / 100, by = .5 / 100)),
        minor_breaks = seq(1.5 / 100, 7 / 100, by = .25 / 100)
      )