# How to create a bar chart using ggplot2 with dots drawn at the center of top edge of the bars in R?

R ProgrammingServer Side ProgrammingProgramming

Aesthetics is one of the most important aspect of a chart, hence we should try to use the best possible aesthetic properties in a plot. In a bar chart, we can represent the center of bars in many ways and one such way is using dots at the center of the top edge of the bars. We can use geom_point function by defining colour argument to put points at the center of top edge of the bars in a bar chart created by using ggplot2.

## Example

Consider the below data frame:

> freq<-c(212,220,218)
> df<-data.frame(x,freq)
> df

## Output

x freq
1 Mango 212
2 Guava 220
3 Pomegranate 218

> library(ggplot2)
> ggplot(df,aes(x,freq))+geom_bar(stat="identity")

## Output:

Creating bar chart with dots drawn at the center of top edge of the bars:

## Example

> ggplot(df,aes(x,freq))+geom_bar(stat="identity")+geom_point(colour="blue",size=5)

## Output:

Published on 07-Nov-2020 07:30:45