# Re: [R] x tick labels - sparse?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat 12 Aug 2006 - 10:34:59 EST

Try this:

x <- seq(-100,1000,25)
y <- x * x
plot(x, y, xaxt = "n")
axis(1, x[x %% 100 == 0])

On 8/11/06, Darren Weber <darrenleeweber@gmail.com> wrote:
> Hi,
>
> I'm stuck on creating a plot with x tick labels for every Nth tick
> mark - how is that done? I don't see a simple solution to this in
> help(plot) or help(par) and what I've tried is not working, eg, the
> following does not work, although it seems intuitive to me that it
> should work:
>
> x <- seq(-100,1000,25)
> y <- x * x
> % find all the x values that are multiples of 100
> tmp <- x / 100
> tmp <- tmp %% 1
> tmp <- tmp > 0
> % set all other values to null strings
> xtickLabels <- as.character( x )
> xtickLabels[tmp] <- ""
> plot(x, y, xlab=xtickLabels)
>
>
> These commands look like this (the plot is not right):
>
> > x <- seq(-100,1000,25)
> > x
> [1] -100 -75 -50 -25 0 25 50 75 100 125 150 175 200 225 250
> [16] 275 300 325 350 375 400 425 450 475 500 525 550 575 600 625
> [31] 650 675 700 725 750 775 800 825 850 875 900 925 950 975 1000
> >
> > tmp <- x / 100
> > tmp
> [1] -1.00 -0.75 -0.50 -0.25 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75
> [13] 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75
> [25] 5.00 5.25 5.50 5.75 6.00 6.25 6.50 6.75 7.00 7.25 7.50 7.75
> [37] 8.00 8.25 8.50 8.75 9.00 9.25 9.50 9.75 10.00
> >
> > tmp <- tmp %% 1
> > tmp
> [1] 0.00 0.25 0.50 0.75 0.00 0.25 0.50 0.75 0.00 0.25 0.50 0.75 0.00 0.25 0.50
> [16] 0.75 0.00 0.25 0.50 0.75 0.00 0.25 0.50 0.75 0.00 0.25 0.50 0.75 0.00 0.25
> [31] 0.50 0.75 0.00 0.25 0.50 0.75 0.00 0.25 0.50 0.75 0.00 0.25 0.50 0.75 0.00
> >
> > tmp <- tmp > 0
> > tmp
> [1] FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE
> [13] FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE
> [25] FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE
> [37] FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE
> >
> > xtickLabels <- as.character( x )
> > xtickLabels
> [1] "-100" "-75" "-50" "-25" "0" "25" "50" "75" "100" "125"
> [11] "150" "175" "200" "225" "250" "275" "300" "325" "350" "375"
> [21] "400" "425" "450" "475" "500" "525" "550" "575" "600" "625"
> [31] "650" "675" "700" "725" "750" "775" "800" "825" "850" "875"
> [41] "900" "925" "950" "975" "1000"
> >
> > xtickLabels[tmp] <- ""
> > xtickLabels
> [1] "-100" "" "" "" "0" "" "" "" "100" ""
> [11] "" "" "200" "" "" "" "300" "" "" ""
> [21] "400" "" "" "" "500" "" "" "" "600" ""
> [31] "" "" "700" "" "" "" "800" "" "" ""
> [41] "900" "" "" "" "1000"
> >
> > y <- x * x
> > y
> [1] 10000 5625 2500 625 0 625 2500 5625 10000
> [10] 15625 22500 30625 40000 50625 62500 75625 90000 105625
> [19] 122500 140625 160000 180625 202500 225625 250000 275625 302500
> [28] 330625 360000 390625 422500 455625 490000 525625 562500 600625
> [37] 640000 680625 722500 765625 810000 855625 902500 950625 1000000
> >
> > plot(x, y, xlab=xtickLabels)
> >
>
>
>
> Best, Darren
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help