R How to Show All Axis Labels of Barchart (2 Examples)

In this R tutorial you’ll learn how to display all text labels of a barchart axis.

Preparing the Examples

data(iris)                           # Load iris
iris_new <- iris[c(1, 51, 101), ]    # Modify iris
iris_new                             # Example data
#     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
# 1            5.1         3.5          1.4         0.2     setosa
# 51           7.0         3.2          4.7         1.4 versicolor
# 101          6.3         3.3          6.0         2.5  virginica
barplot(iris_new$Petal.Length ~      # Draw regular barplot in Base R
          iris_new$Species)

r graph figure 1 r show all axis labels barchart programming language

Example 1: Reducing Size & Changing Angle to Display All Axis Labels of Base R Plot

barplot(iris_new$Petal.Length ~      # Barplot with smaller labels
          iris_new$Species,
        las = 2,
        cex.names = 0.5)

r graph figure 2 r show all axis labels barchart programming language

Example 2: Reducing Size & Changing Angle to Display All Axis Labels of ggplot2 Plot

install.packages("ggplot2")          # Install & load ggplot2 package
library("ggplot2")
ggplot(iris_new,                     # Barplot with smaller labels
       aes(Species,
           Petal.Length)) +
  geom_bar(stat = "identity") +
  theme(axis.text.x = element_text(angle = 90,
                                   size = 5))

r graph figure 3 r show all axis labels barchart programming language

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top