# How to create a transparent histogram using ggplot2 in R?

R ProgrammingServer Side ProgrammingProgramming

#### Artificial Intelligence : The Future Of Programming

15 Lectures 54 mins

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### C Programming from scratch- Master C Programming

Best Seller

60 Lectures 8 hours

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)

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

Updated on 08-Oct-2020 15:23:20