Tutorial for Bar Plot in ggplot2 with Examples

Syntax of Bar Plot in ggplot2

In ggplot2, the following is the minimal syntax for generating the bar plot  –

ggplot(<data>, mapping = aes(<mapping>) + geom_bar()

You can customize the bar plot by adding more layers such as themes, labs, etc.

Loading ggplot2

The ggplot2 library can be loaded with the below line.
In [1]:

In the below example, we are plotting the very basic bar plot in ggplot2 by passing the dataset along with the mapping of attributes for x and y.

Example 2: Horizontal Bar Plot

horizontal bar plot in R ggplot2 Example



  • 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.

Follow Us

Leave a Reply

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