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.
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)).
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.
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.
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With