Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the spacing of tick marks on the axis of a plot?

Tags:

plot

r

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?

like image 339
skan Avatar asked Sep 24 '10 07:09

skan


People also ask

How do you change the axis tick marks in R?

Option 1. Set xaxt = "n" and yaxt = "n" to remove the tick labels of the plot and add the new labels with the axis function. Note that the at argument sets where to show the tick marks.

What is tick spacing?

The small vertical lines that calibrate a slider are called tick marks. The longer, thicker marks are major ticks and the thinner marks are minor ticks. The major ticks can be labeled. The spacing between major ticks is set with: setMajorTickSpacing(int spacing)

How do you add a tick mark in Axis?

Add tick marks on an axisClick Add Chart Element > Axes > More Axis Options. On the Format Axis pane, expand Tick Marks, and then click options for major and minor tick mark types. After you add tick marks, you can change the intervals between the tick marks by changing the value in the Interval between marks box.


1 Answers

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 intervals between the tick marks (n). Accordingly, n+1 is the number of tick marks drawn. (This 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.

like image 175
Henrik Avatar answered Sep 19 '22 01:09

Henrik