- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a bar plot using ggplot2 with one bar having black border in R?
The bar plot can be easily created with the help of geom_bar. But if we want to have a different border for a particular bar then we first need to create the bar plot and store it in an object. After that we need to add the original plot with the bar for which we want to have a black border. Check out the below example to understand how it can be done.
Example
Consider the below data frame:
> Group<-c("G1","G2","G3") > Freq<-c(18,27,24) > df<-data.frame(Group,Freq) > df
Output
Group Freq 1 G1 18 2 G2 27 3 G3 24
Loading ggplot2 package and creating a bar plot:
Example
> library(ggplot2) > p<-ggplot(df,aes(Group,Freq,fill=Group))+geom_bar(stat="identity") > p
Output:
Adding the bar plot with bar having black color border:
Example
> p+geom_bar(data=df[(df$Group=="G2"),],stat="identity", + aes(Group),size=3,color="black")
Output:
- Related Articles
- How to create a bar plot with ggplot2 using stat_summary in R?
- How to create transparent bar plot using ggplot2 in R?
- How to create bar plot with log values using ggplot2 in R?
- How to create bar plot with gradient colors using ggplot2 in R?\n
- How to create a stacked bar plot with vertical bars in R using ggplot2?
- How to create a bar plot using ggplot2 with percentage on Y-axis in R?
- Create bar plot of one column in an R data frame using ggplot2.
- How to create the stacked bar plot using ggplot2 in R with labels on the plot?
- How to create bar plot using ggplot2 with structure data frame?
- How to create a horizontal bar graph using ggplot2 in R?
- How to create bar plot of means with error bars of standard deviations using ggplot2 in R?
- How to create bar chart using ggplot2 with chart sub-title in R?
- How to create the bar chart with ggplot2 using color brewer in R?
- How to create a bar plot in R with label of bars on top of the bars using ggplot2?
- How to reverse the bars of a bar plot a using ggplot2 in R?

Advertisements