- 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 chart for single vector using ggplot2 in R?
To create a bar chart for single vector using ggplot2 in R, we can follow the below steps −
- First of all, create a vector and melt it using melt function of reshape2 package and save the melted data.
- Then, create the bar chart with melted data using ggplot2.
Create the vector and melt it
Creating the vector and using melt function of reshape2 to melt the data in vector −
x<-rpois(10,5) library(reshape2) x_melted<-melt(x) x_melted
On executing, the above script generates the below output(this output will vary on your system due to randomization)−
value 1 4 2 5 3 8 4 5 5 7 6 5 7 3 8 7 9 7 10 6
Create the bar chart
Using melted data to create the bar chart and using seq_along function to display X-axis values −
x<-rpois(10,5) library(reshape2) x_melted<-melt(x) library(ggplot2) ggplot(x_melted,aes(x=seq_along(x),y=x))+geom_bar(stat="identity")
Output
- Related Articles
- 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 point chart for cumulative sums using ggplot2 in R?
- How to create a bar chart using plotly in R?
- Create stacked bar chart with percentages on Y-axis using ggplot2 in R.
- How to create a horizontal bar graph using ggplot2 in R?
- How to create transparent bar plot using ggplot2 in R?
- How to create stacked bar chart using ggvis in R?
- How to create a bar plot with ggplot2 using stat_summary in R?
- How to create a horizontal bar chart using ggplot2 with labels at inside end of the bars in R?
- How to create a point chart with empty points using ggplot2 in R?
- How to create a line chart using ggplot2 with larger width in R?
- How to create a line chart for a subset of a data frame using ggplot2 in R?
- How to create a bar chart using ggplot2 with facets that are in the order of the data in R?
- How to create horizontal stacked bar chart using ggvis in R?

Advertisements