Renaming the group labels
The names.arg attribute can be renamed to assign a new set of labels to the x-axis arguments.
Example: Renaming the group labels
R
# creating a data frame data_frame <- data.frame (col1 = 1:5, col2 = 5:9, col3 = 1) # printing the data frame print ( "Original DataFrame" ) print (data_frame) # plotting a barplot barplot (data_frame$col2, names.arg = c ( "Grp1" , "Grp2" , "Grp3" , "Grp4" , "Grp5" )) |
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)