- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- 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 barplot with gaps on Y-axis scale in R?

If we want to have gaps on Y-axis scale in a barplot then it cannot be done in base R. For this purpose, we can make use of gap.barplot function of plotrix package. The gap.barplot function is very handy, we just need to pass the vector for which we want to create the barplot and the gap values simply by using gap argument.

Loading plotrix package:

> library(plotrix)

## Example1

> x<-rpois(20,5) > x

## Output

[1] 2 6 5 4 7 2 5 2 5 2 8 6 8 13 3 5 7 7 5 6

> gap.barplot(x,gap=c(2,4)) ylim 0 11

Warning message:

In gap.barplot(x, gap = c(2, 4)) : gap includes some values of y

## Output:

## Example2

> y<-sample(0:50,10) > y

## Output

[1] 8 50 45 35 25 12 40 41 14 32

> gap.barplot(y,gap=c(20,30)) ylim -2 40

Warning message:

In gap.barplot(y, gap = c(20, 30)) : gap includes some values of y

## Output:

- Related Questions & Answers
- How to exponentially scale the Y axis with matplotlib?
- How to create a bar plot using ggplot2 with percentage on Y-axis in R?
- Create ggplot2 graph with reversed Y-axis and X-axis on top in R.
- How to create cumulative sum chart with count on Y-axis in R using ggplot2?
- How to create a plot with reversed Y-axis labels in base R?
- Create stacked bar chart with percentages on Y-axis using ggplot2 in R.
- How to create stacked barplot using barplot function in R?
- How to plot values with log scales on x and y axis or on a single axis in R?
- A scale transform the element by using y-axis with CSS3
- How to create a histogram with Y-axis values as count using ggplot2 in R?
- How to create bar plot in base R with different limits for Y-axis?
- How to create facetted scatterplot with scale of X-axis based on the numerical values corresponding to grouping column in R?
- How to create stacked barplot using barplot function with each bar having unique color in R?
- How to change the scale of Y-axis if the histogram bars are higher than the axis size in R?
- How to create a plot in base R with dates sequence on X-axis?

Advertisements