- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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 display 0 at Y-axis using ggplot2 in R?
To display 0 at Y-axis, we can set the limits for Y-axis using scale_y_continuous function of ggplot2 package. For example, if we have two columns say x and y in an R data frame called df then the scatterplot with displaying 0 at Y-axis can be created by using the below command
ggplot(df,aes(x,y))+geom_point()+scale_y_continuous(limits=c(0,”upperlimit”))
Consider the below data frame −
Example
x<-rpois(20,5) y<-rpois(20,5) df<-data.frame(x,y) df
Output
x y 1 5 9 2 7 4 3 5 3 4 6 6 5 6 5 6 6 4 7 4 8 8 9 6 9 6 5 10 8 3 11 2 6 12 10 6 13 5 3 14 1 6 15 5 3 16 5 6 17 5 1 18 4 2 19 2 7 20 4 10
Loading ggplot2 package and creating scatterplot of x and y −
Example
library(ggplot2) ggplot(df,aes(x,y))+geom_point()
Output
Creating the scatterplot of x and y with display of 0 on Y-axis −
Example
ggplot(df,aes(x,y))+geom_point()+scale_y_continuous(limits=c(0,12))
Output
- Related Articles
- How to display Y-axis with Euro sign using ggplot2 in R?
- How to display count on Y-axis for line chart using ggplot2 in R?
- How to set the Y-axis tick marks using ggplot2 in R?
- How to change the Y-axis title to horizontal using ggplot2 in R?
- How to display average line for y variable using ggplot2 in R?
- How to display positive sign for X-axis labels in R using ggplot2?
- How to create different Y-axis for group levels using ggplot2 in R?
- How to change the text size of Y-axis title using ggplot2 in R?
- How to change the Y-axis values in a bar plot using ggplot2 in R?
- How to create cumulative sum chart with count on Y-axis in R using ggplot2?
- How to create a bar plot using ggplot2 with percentage on Y-axis in R?
- How to change the Y axis limit for boxplot created by using ggplot2 in R?
- How to create a histogram with Y-axis values as count using ggplot2 in R?
- How to reduce the space between Y-axis value and ticks using ggplot2 in R?
- How to represent all values of X-axis or Y-axis on the graph in R using ggplot2 package?

Advertisements