 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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)

Advertisements
 