tags:

views:

150

answers:

2

Hello

How can I change the spacing of tick marks on the axis of a plot?

What parameters should I use with base plot or with rgl?

cheers

+2  A: 

There are at least two ways for achieving this in base graph (my examples are for the x-axis, but work the same for the y-axis):

  1. Use par(xaxp = c(x1, x2, n)) or plot(..., xaxp = c(x1, x2, n)) to define the position (x1 & x2) of the extreme tick marks and the number of tick marks (n). (works only if you use no logarithmic scale, for the behavior with logarithmic scales see ?par).

  2. You can suppress the drawing of the axis altogether and add the tick marks later with axis().
    To suppress the drawing of the axis use plot(... , xaxt = "n").
    Then call axis() with side, at, and labels: axis(side = 1, at = v1, labels = v2). With side referring to the side of the axis (1 = x-axis, 2 = y-axis), v1 being a vector containing the position of the ticks (e.g., c(1, 3, 5) if your axis ranges from 0 to 6 and you want three marks), and v2 a vector containing the labels for the specified tick marks (must be of same length as v1, e.g., c("group a", "group b", "group c")). See ?axis and my updated answer to a post on stats.stackexchange for an example of this method.

Henrik
+1  A: 

With base graphics, the easiest way is to stop the plotting functions from drawing axes and then draw them yourself.

plot(1:10, 1:10, axes = FALSE)
axis(side = 1, at = c(1,5,10))
axis(side = 2, at = c(1,3,7,10))
box()
Gavin Simpson
HelloI have datetime data on the x axis, (chron)In my case I think it should be a better way than writing a line with let say 25 full dates.What If I want the dates writen vertically on the x axis, I mean perpendicularly.cheers
Look at graphics parameter `las` in ?par which can be added to a call to `axis()`, and which controls the orientation of the tick labels. E.g. `axis(side = 1, at = c(1,5,10), las = 2)`. You might want to investigate whether there is an `axis()` function for chron objects or consider using R's Date Time classes, which already have `axis()` functions (e.g. `axis.Date()` for the class '"Date"').
Gavin Simpson