Tutorial of Barplot in Base R Programming Language

Following is the basic syntax of barplot() function in R with some important arguments. The detailed syntax can be found here.

barplot(height, xlab, ylab, main, names.arg, col)

  • height – It is a vector or matrix that contains the value used for creating the bar of the plot.
  • xlab – It sets the label for x axis.
  • ylab – It sets the label for y axis.
  • main – It set the title of the barplot.
  • names.arg – It sets the names under each bar.
  • col – It is used for assigning colors to the bar plot.
Out[3]:

Example – 4: Coloring the Barplot with Multiple Colors

The coloring of the barplot with multiple colors can be done as shown in the below example.

The title of the barplot can be added with ‘main’ parameter and the x & y title can be added with ‘xlab’ and ‘ylab’ parameters respectively.

Let us now use the above data to create a grouped bar chart as shown below.
  • Veer Kumar

    I am passionate about Analytics and I am looking for opportunities to hone my current skills to gain prominence in the field of Data Science.

    View all posts

Follow Us

Leave a Reply

Your email address will not be published. Required fields are marked *