- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Change the starting point of bars in bar plot for a ggplot2 graph in R.
To change the starting point of bars in bar plot for a ggplot2 graph in R, we can use coord_cartesian function of ggplot2 package with ylim argument where we can change the starting and ending point for the bar plot values.
Check out the Example given below to understand how it can be done.
Example
Following snippet creates a sample data frame −
x<-c("A","B") y<-c(45,42) df<-data.frame(x,y) df
The following dataframe is created
x y 1 A 45 2 B 42
To load ggplot2 package and create bar plot for data in df on the above created data frame, add the following code to the above snippet −
x<-c("A","B") y<-c(45,42) df<-data.frame(x,y) library(ggplot2) ggplot(df,aes(x,y))+geom_bar(stat="identity")
Output
If you execute all the above given snippets as a single program, it generates the following Output −
To create bar plot for data in df with bar starting at 10 on the above created data frame, add the following code to the above snippet −
x<-c("A","B") y<-c(45,42) df<-data.frame(x,y) library(ggplot2) ggplot(df,aes(x,y))+geom_bar(stat="identity")+coord_cartesian(ylim=c(10,50))
Output
If you execute all the above given snippets as a single program, it generates the following Output −
- Related Articles
- How to change the color of bars of a bar plot using ggplot2 in R?
- How to reverse the bars of a bar plot a using ggplot2 in R?
- How to change the thickness of the borders of bars in 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?
- How to increase the space between bars of a bar plot using ggplot2 in R?
- How to create a bar plot in R with label of bars on top of the bars using ggplot2?
- How to change the plot border color of a ggplot2 graph in R?
- How to create a stacked bar plot with vertical bars in R using ggplot2?
- Change the outline color for histogram bars using ggplot2 in R.
- How to change the Y-axis values in a bar plot using ggplot2 in R?
- How to create bar plot of means with error bars of standard deviations using ggplot2 in R?
- How to create a bar plot with bars for missing values in R?
- How to change the automatic sorting of X-axis of a bar plot using ggplot2 in R?
- How to change legend values in a bar plot created by using ggplot2 in R?
- How to change the order of bars in bar chart in R?
