# How to show all X-axis labels in a bar graph created by using barplot function in R?

R ProgrammingServer Side ProgrammingProgramming

#### Artificial Intelligence : The Future Of Programming

15 Lectures 54 mins

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### C Programming from scratch- Master C Programming

Best Seller

60 Lectures 8 hours

In base R, the barplot function easily creates a barplot but if the number of bars is large or we can say that if the categories we have for X-axis are large then some of the X-axis labels are not shown in the plot. Therefore, if we want them in the plot then we need to use las and cex.names.

## Example

Consider the below data and bar graph −

Live Demo

> x<-sample(1:5,20,replace=TRUE)
> names(x)<-rep(c("IN","CO","LA","NY"),times=5)
> barplot(x)

## Output

Showing all the X-axis labels −

> barplot(x,las=2,cex.names=0.5)

## Output

Updated on 07-Sep-2020 05:51:30