How to plot two histograms together in R?

Consider the below data frames −

> glucose   fructose 

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   fructose$sweetener  sweeteners 

Now let’s create the histograms

> library(ggplot2)
> ggplot(sweeteners, aes(length, fill = sweetener)) + geom_density(alpha = 0.2)

Updated on: 2020-07-06T14:41:01+05:30

412 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements