- 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 plot two histograms together in R?
Consider the below data frames −
> glucose <- data.frame(length = rnorm(100, 2.5)) > fructose <- data.frame(length = rnorm(500, 2.5))
We need to combine these two data frames but before that we have to make a new column in each of these data frames to create their identification
> glucose$sweetener <- 'glucose' > fructose$sweetener <- 'fructose' > sweeteners <- rbind(glucose, fructose)
Now let’s create the histograms
> library(ggplot2) > ggplot(sweeteners, aes(length, fill = sweetener)) + geom_density(alpha = 0.2)
- Related Articles
- How to plot two histograms side by side using Matplotlib?
- How to visualize two categorical variables together in R?
- How to plot histograms from dataframes in Pandas using Matplotlib?
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- How to create facetted histograms using ggplot2 in R?
- How to create side by side histograms in base R?
- How to plot histograms of different colors of an image in OpenCV Python?
- How to compute and plot 2D histograms of an image in OpenCV Python?
- How to change legend for multiple histograms using ggplot2 in R?
- How to create two line charts in the same plot in R?
- How to compare histograms of two images using OpenCV Python?
- How to make two histograms have the same bin width in Matplotlib?
- How to plot a function in R?
- How to create ACF plot in R?
- How to write plot description outside plot in facetted plot using ggplot2 in R?

Advertisements