- 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
How to create a bar graph using ggplot2 without horizontal gridlines and Y-axes labels in R?
A bar graph plotted with ggplot function of ggplot2 shows horizontal and vertical gridlines. If we are interested only in the bar heights then we might prefer to remove the horizontal gridlines. In this way, we can have X-axis that helps us to look at the different categories we have in our variable of interest and get rid of the unnecessary information. This can be done by setting breaks argument to NULL in scale_y_discrete function.
Example
Consider the below data frame −
> x<-1:5 > y<-c(20,18,10,15,17) > df<-data.frame(x,y)
Loading ggplot2 package −
> library(ggplot2)
Creating the plot with all gridlines −
> ggplot(df,aes(x,y))+ + geom_bar(stat='identity')
Output
Creating the plot without horizontal gridlines −
> ggplot(df,aes(x,y))+ + geom_bar(stat='identity')+ + scale_y_discrete(breaks = NULL)
Output
- Related Articles
- Create a graph using ggplot2 without axes ticks and axes labels.
- Create a ggplot2 graph without axes labels, axes titles and ticks in R.
- How to create a horizontal bar graph using ggplot2 in R?
- How to create a dotchart using ggplot2 without gridlines in R?
- Create ggplot2 graph with darker axes labels, lines and titles in R
- How to create a horizontal bar chart using ggplot2 with labels at inside end of the bars in R?
- How to create boxplot in base R without axes labels?
- R Programming how to display both axes’ labels of a ggplot2 graph in italics?
- Create darker gridlines in theme_bw for a ggplot2 graph in R.
- Create a graph without background panel using ggplot2 in R.
- How to create a ggplot2 graph in R without showing values?
- How to create a dashed horizontal line in a ggplot2 graph in R?
- How to display axes ticks and labels inside the plot using ggplot2 in R?
- How to create a boxplot using ggplot2 for single variable without X-axis labels in R?
- How to extract axes labels for the plot drawn using ggplot2 in R?

Advertisements