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)
Contact Us