![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 change the Y-axis values in a bar plot using ggplot2 in R?
Bar plot is frequently used to analyze the number of times a level of factor variable occurs in a data set and the Y-axis values are crucial to the bar plot. Sometimes these values are not in the form we want, therefore, we want to replace them with the new ones. This can be done with the help of breaks argument of scale_y_continuous function in ggplot2.
Example
Consider the below data frame −
> set.seed(1) > x<-rpois(50,5) > df<-data.frame(x)
Loading ggplot2 package −
> library(ggplot2)
Creating the plot without specifying the Y-axis values −
> ggplot(df,aes(x))+ + geom_bar()
Output
Plotting with new Y-axis values −
> ggplot(df,aes(x))+ + geom_bar()+ + scale_y_continuous(breaks=c(0,2,4,6,8,10))
Output
Advertisements