- 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 colored barplot using ggplot2 without legend entries in R?
When we create a colored barplot using ggplot2 the legend entries are automatically created. If we want to create the plot without those legend entries then theme function can be used. For example, if we have a data frame df that contains x as categorical variable and y as count variable then barplot without legend entries can be created as:
ggplot(df,aes(x,y,fill=x))+geom_bar(stat="identity")+theme(legend.position="none")
Example
Consider the below data frame:
> x<-c("A","B","C","D","E") > y<-c(24,28,25,27,26) > df<-data.frame(x,y) > df
Output
x y 1 A 24 2 B 28 3 C 25 4 D 27 5 E 26
Loading ggplot2 package and creating the barplot:
> library(ggplot2) > ggplot(df,aes(x,y,fill=x))+geom_bar(stat="identity")
Output:
Creating the barplot without legend entries:
> ggplot(df,aes(x,y,fill=x))+geom_bar(stat="identity")+theme(legend.position="none")
Output:
- Related Articles
- How to create horizontal legend using ggplot2 in R?
- How to create blue or red colored boxplots in R using ggplot2?
- How to create stacked barplot using barplot function in R?
- How to create boxplot using ggplot2 without whiskers in R?
- How to create a dotchart using ggplot2 without gridlines in R?
- How to create scatterplot using ggplot2 without grey background in R?
- How to create boxplot using ggplot2 without box border in R?
- How to change the legend shape using ggplot2 in R?
- How to display legend on top using ggplot2 in R?
- How to create a colored frame for ggplot2 graph in R?\n
- How to cover legend in a box using ggplot2 in R?
- How to change legend for multiple histograms using ggplot2 in R?
- How to display negative labels below bars in barplot using ggplot2 in R?
- How to create a scatterplot in R with legend position inside the plot area using ggplot2?
- Create a graph without background panel using ggplot2 in R.

Advertisements