-1

While using ggplot in R, how does it mark the value for the ticks in the x and y axis? My x-axis data is from -4 to 5, but all the ticks are not getting marked in the plot. It just marks -4, 0 and 4.

markus
  • 25,843
  • 5
  • 39
  • 58
Vishal
  • 1
  • 1
  • 2
    add a minimal example and have a search of the documentation (hint: try `scale_x_continuous`) – bob1 Oct 29 '18 at 21:07
  • 1
    scale_x_continuous(breaks=-4:5) – iod Oct 29 '18 at 21:08
  • 3
    Possible duplicate of [Increase number of axis ticks](https://stackoverflow.com/questions/11335836/increase-number-of-axis-ticks) – markus Oct 29 '18 at 21:12

1 Answers1

0

Suppose this is your raw data:

test <- data.frame(-4:5, 1:10)
names(test) <- c("x","y")

The default plot looks like this:

p1 <- ggplot(test, aes(x,y)) + geom_point()
p1

You can then use scale_x_continuous to change the tick markings:

p1 +  scale_x_continuous(breaks = seq(-4,5, by = 1))

Hope this helps.

Jiafei Li
  • 53
  • 7
  • @Vishal I'm glad to hear that. It your problem is solved, please give my answer a checkmark to save others' time. – Jiafei Li Nov 08 '18 at 02:12