Adding axis labels

The xlab and ylab attributes contain character strings, which assign the respective names to the axes of the bar plots. 

Example: Adding axis labels

R




# creating a data frame
data_frame <- data.frame(col1 = 1:20,
                         col2 = 1:20,
                         col3 = 1)
  
# printing the data frame
print ("Original DataFrame")
print (data_frame)
  
# plotting a barplot
barplot(data_frame$col2, names.arg = data_frame$col1 ,
        xlab = "Integers", ylab = "Numbers")


Output:



How to customize the axis of a Bar Plot in R

Barplots in R programming language can be created using the barplot() method. It takes as input a matrix or vector of values. The bar heights are equivalent to the values contained in the vector. 

Syntax: barplot(H, xlab, ylab, main, names.arg, col)

Similar Reads

Labeling the X-axis of the bar plot

The names.args attribute in the barplot() method can be used to assign names to the x-axis labels. Numeric or character labels can be assigned which are plotted alternatively on the display window....

Setting the Y-axis limit of the bar plot

...

Setting the X-axis limit of the bar plot

The ylim parameter of the barplot() method can be used to set limits to portray on the display window. It contains a vector containing lower and higher limit....

Plotting logarithmic Y-axis

...

Plotting logarithmic X-axis

The xlim parameter of the barplot() method can be used to set limits to portray on the display window. It contains a vector containing lower and higher limit....

Renaming the group labels

...

Adding label orientation

The log parameter can be set to display the axis and its corresponding values on the logarithmic scale. Setting the log value equivalent to character string y displays the modifications on the y axis....

Adding axis labels

...

Contact Us