- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change the gridlines of Y-axis on a chart created by using ggplot2 in R?
Normally, the gridlines on a plot created by using ggplot2 package are a little far from each other but sometimes the plot looks better if the gridlines are close to each other, therefore, we might want to do so. This can be done by setting the minor_breaks and breaks using scale_y_continuous if the Y-axis plots a continuous variable.
Consider the below data frame −
> x<-sample(1:100,20) > y<-sample(1:50,20) > df<-data.frame(x,y) > df
x y 1 14 16 2 36 1 3 78 18 4 61 6 5 19 11 6 2 40 7 93 23 8 10 13 9 3 21 10 55 31 11 75 28 12 51 33 13 13 12 14 80 37 15 98 49 16 66 39 17 79 10 18 52 38 19 74 47 20 12 9
Loading ggplot2 package and creating a scatterplot between x and y −
> library(ggplot2) > ggplot(df,aes(x,y))+geom_point()
Changing the gridlines in the plot −
> ggplot(df,aes(x,y))+geom_point()+scale_y_continuous(minor_breaks=seq(0,50,2),breaks =seq(0,50,2))
- How to change the Y axis limit for boxplot created by using ggplot2 in R?
- How to display count on Y-axis for line chart using ggplot2 in R?
- How to create cumulative sum chart with count on Y-axis in R using ggplot2?
- Create stacked bar chart with percentages on Y-axis using ggplot2 in R.
- How to create gridlines that matches with Y-axis values in the plot created by using plot function in R?
- How to change the Y-axis title to horizontal using ggplot2 in R?
- How to change the text size of Y-axis title using ggplot2 in R?
- How to reverse the X-axis labels of scatterplot created by using ggplot2 in R?
- How to change the Y-axis values in a bar plot using ggplot2 in R?
- How to change the size of dots in dotplot created by using ggplot2 in R?
- How to change the color of gridlines of a ggplot2 graph in R?
- How to change the abline colour created using ggplot2 in R?
- How to change the angle of annotated text in plot created by using ggplot2 in R?
- How to change legend values in a bar plot created by using ggplot2 in R?
- How to change the bars color to grey shade of a bar graph created by using ggplot2 in R?