Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling both the major and minor grid lines on the y axis

Tags:

r

ggplot2

library(ggplot2) x <- c(1:100) y <- c(1:100) ch1 <- qplot(x, y) ch2 <- ch1 +         theme(panel.grid.minor = element_line(colour = "white", size = 0.5)) +         scale_y_continuous(minor_breaks = seq(0, 100, 5)) ch2  

I am making a chart with ggplot and can control the y axis minor grid lines. But what do I have to do to contol the y axis major grid lines as well so they are not set automatically (for example in units of 10s, so lines and y unit labels at 10,20,30 etc)? I tried major_breaks = seq(0 , 100, 10) but it did not work. Thank you for your help.

like image 755
adam.888 Avatar asked Aug 06 '13 13:08

adam.888


People also ask

What are major and minor gridlines?

On value axes, major grid lines are drawn for every major axis division. Minor grid lines separate the units delineated by major grid lines. Minor grid lines, which can only appear on value axes, appear for every minor axis division. By default, major grid lines appear for value axes.

What is the function of minor gridlines?

Minor gridlines are horizontal and vertical lines that run through your chart layout to represent axis divisions. They are very useful for quickly calculating the height or breadth of visual components used in our chart.

How do I get rid of grid lines in R?

To remove a particular panel grid, use element_blank() for the corresponding theme argument. For example to remove the major grid lines for the x axis, use this: p + theme(panel. grid.


1 Answers

It's just breaks:

ch1 + theme(panel.grid.minor = element_line(colour="white", size=0.5)) +     scale_y_continuous(minor_breaks = seq(0 , 100, 5), breaks = seq(0, 100, 10)) 

a plot with major breaks

like image 188
Peyton Avatar answered Sep 19 '22 15:09

Peyton