Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...