Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - ggplot2 - setting tick mark interval [duplicate]

Tags:

r

ggplot2

For a ggplot I need to get tick marks with labels for intervals at 10 instead of 20 as shown in the image below - how to get tick marks with labels at intervals of 10 for x-axis and intervals of 5 for y-axis

The original x axis vector has data like [10, 20, 30, 40, 50, 60] for all series and y-axis vector has data like [1.67, 3.3, 5, 6.67, 8.3,10] for one series and like-wise for other two series.

ggplot below

like image 840
user3206440 Avatar asked Jun 21 '16 17:06

user3206440


People also ask

How do I specify tick marks in ggplot2?

The default value of Y-axis tick marks using ggplot2 are taken by R using the provided data but we can set it by using scale_y_continuous function of ggplot2 package. For example, if we want to have values starting from 1 to 10 with a gap of 1 then we can use scale_y_continuous(breaks=seq(1,10,by=1)).

How do I change the y axis values in ggplot2?

Use scale_xx() functions It is also possible to use the functions scale_x_continuous() and scale_y_continuous() to change x and y axis limits, respectively.

How do I add a minor tick in ggplot2?

To adjust the number of minor ticks, you just change the number of minor breaks using the minor_breaks argument of the continuous scale functions. The vector you give the minor_breaks argument will define the position of each minor tick.


1 Answers

I advise you to add some of your code, so that it is easier for people to help you here.

To answer your question, you could use the breaks option in the scale family. For instance,

g <- ggplot(...) + ...
g + scale_x_continuous(breaks = seq(10, 60, by = 10))
  + scale_y_continuous(breaks = seq(0, 10, len = 5))
like image 60
Boxuan Avatar answered Oct 01 '22 18:10

Boxuan