How to change the thickness of the borders of bars in bar plot created by using ggplot2 in R?


The border thickness highlights the bars and this could be useful in situations where we have similar frequencies. If we want to change the thickness of the bars then size argument under geom_bar function of ggplot2 package can be used and it can be set according to our need starting from 1.

Example

Consider the below data frame −

x<−c("Male","Female")
F<−c(24,28)
df<−data.frame(x,F)
df

Output

   x    F
1 Male 24
2 Female 28

Loading ggplot2 package and creating bar plot for x −

library(ggplot2)
ggplot(df,aes(x,F,color=x))+geom_bar(stat="identity")

Output

Creating the same plot with a little bit larger border size −

ggplot(df,aes(x,F,color=x))+geom_bar(stat="identity",size=2)

Output

Creating the same plot with a very large border size −

ggplot(df,aes(x,F,color=x))+geom_bar(stat="identity",size=5)

Output

Updated on: 07-Nov-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements