- 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
Create bar plot of one column in an R data frame using ggplot2.
To create bar plot of one column in an R data frame using ggplot2, we can use rownames of the data frame as x variable in aes.
For Example, if we have a data frame called df that contains two columns say X and Y and we want to create the bar plot of values in Y then we can use the below mentioned command −
ggplot(df,aes(rownames(df),Y))+geom_bar(stat="identity")
Example
Following snippet creates a sample data frame −
x1<-rpois(5,10) x2<-rpois(5,2) x3<-rpois(5,5) df<-data.frame(x1,x2,x3) df
The following dataframe is created
x1 x2 x3 1 9 2 7 2 9 2 3 3 13 1 3 4 13 3 8 5 11 1 1
To load ggplot2 package and create bar plot for data in column x2 of df on the above created data frame, add the following code to the above snippet −
x1<-rpois(5,10) x2<-rpois(5,2) x3<-rpois(5,5) df<-data.frame(x1,x2,x3) library(ggplot2) ggplot(df,aes(rownames(df),x2))+geom_bar(stat="identity")
Output
If you execute the above given snippet, it generates the following Output −
- Related Articles
- How to create bar plot using ggplot2 with structure data frame?
- How to create a bar plot using ggplot2 with one bar having black border 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 a bar plot with ggplot2 using stat_summary in R?
- How to create facetted plot with one facet displaying all data using ggplot2 in R?
- How to create bar plot with gradient colors using ggplot2 in R?\n
- How to create an empty plot using ggplot2 in R?
- How to create the stacked bar plot using ggplot2 in R with labels on the plot?
- 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?
- How to create bar plot of means with error bars of standard deviations using ggplot2 in R?
- Create stacked bar plot for one categorical variable in an R dataframe.
- Create an integer column in an R data frame with leading zeros
- How to create a lagged column in an R data frame?

Advertisements