- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 transparent histogram using ggplot2 in R?
When we create a histogram using ggplot2 package, the area covered by the histogram is filled with grey color but we can remove that color to make the histogram look transparent. This can be done by using fill="transparent" and color="black" arguments in geom_histogram, we need to use color argument because if we don’t use then the borders of the histogram bars will also be removed and this color is not restricted to black color only.
Example
Consider the below data frame −
set.seed(987) x<-rnorm(10000,2,1.5) df<-data.frame(x)
Loading ggplot2 package and creating histogram of x −
library(ggplot2) ggplot(df,aes(x))+geom_histogram(bins=30)
Output
Creating the transparent histogram −
ggplot(df,aes(x))+geom_histogram(bins=30,fill="transparent",color="black")
Output
- Related Articles
- How to create a transparent polygon using ggplot2 in R?
- How to create a step histogram using ggplot2 in R?
- How to create transparent bar plot using ggplot2 in R?
- How to create histogram with varying binwidth using ggplot2 in R?
- How to create a histogram with Y-axis values as count using ggplot2 in R?
- How to display mean in a histogram using ggplot2 in R?
- How to create a histogram using weights in R?
- How to define the breaks for a histogram using ggplot2 in R?
- How to display the curve on the histogram using ggplot2 in R?
- How to fill histogram bars using ggplot2 in R with different colors?
- How to create a dot plot using ggplot2 in R?
- How to create horizontal legend using ggplot2 in R?
- How to create facetted histograms using ggplot2 in R?
- How to create transparent boxplot in R?
- How to create horizontal histogram in R?

Advertisements