buhtz
buhtz

Reputation: 12202

Why are all relevant tick-marks not plotted on the X-axis?

I often determine that when plotting in R not all relevant tick-marks are drawn. Relevant here means that there is data present.

See this example

> set.seed(NULL)
> d <- data.frame(a=sample(1:10, replace=TRUE), b=sample(11:30))
> plot(d)

The resulting plot where you can see values on the X-axis at 3, 5, 7 and 9. But the tick-marks for them are missing.

enter image description here

The focus of my question is to understand why R acts like that. What is the algorithm and logic behind it?

btw: I know how to solve it. I can draw the X-axis myself. But that is not part of the question.

Upvotes: 0

Views: 94

Answers (1)

Edgar Santos
Edgar Santos

Reputation: 3512

You could find a brief description of the algorithm for plotting the tick marks using?axis.

plot() is a generic function to plot a wide sort of data. In your example, you are using discrete data. For continuous data, it does not make much sense to have a single tick mark for every single value, which would make unreadable the axes. However, you can easily adjust the ticks in your plot using axis()

Upvotes: 1

Related Questions