Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have the code in R for 4 histograms and I wanted to know how to graph them all

ID: 3154480 • Letter: I

Question

I have the code in R for 4 histograms and I wanted to know how to graph them all together so they overlap. Here is the code for the 4 different histograms:

plot1 <- qplot(Boston.Housing$Med.Value, geom="histogram", binwidth=0.5,
main="Histogram of Median Home Value Based on Boston Housing Data",
color=I("black"), fill=I("purple"), xlab="Median Value")
plot2 <- qplot(Boston.Housing$Med.Value, geom="histogram", binwidth=1,
main="Histogram of Median Home Value Based on Boston Housing Data",
color=I("black"), fill=I("purple"), xlab="Median Value")
plot3 <- qplot(Boston.Housing$Med.Value, geom="histogram", binwidth=1.5,
main="Histogram of Median Home Value Based on Boston Housing Data",
color=I("black"), fill=I("purple"), xlab="Median Value")
plot4 <- qplot(Boston.Housing$Med.Value, geom="histogram", binwidth=2,
main="Histogram of Median Home Value Based on Boston Housing Data",
color=I("black"), fill=I("purple"), xlab="Median Value")

Any help would be much appreciated!!!

Explanation / Answer

First write the code for the first histogram in the console as u have written.

Then from the next historam U just write "add = TRUE" within "(...)" every code of the rest of codes .

Like,

plot1 <- qplot(Boston.Housing$Med.Value, geom="histogram", binwidth=0.5,
               main="Histogram of Median Home Value Based on Boston Housing Data",
               color=I("black"), fill=I("purple"), xlab="Median Value")

plot2 <- qplot(Boston.Housing$Med.Value, geom="histogram", binwidth=1,
main="Histogram of Median Home Value Based on Boston Housing Data",
color=I("black"), fill=I("purple"), xlab="Median Value",add=TRUE)
plot3 <- qplot(Boston.Housing$Med.Value, geom="histogram", binwidth=1.5,
main="Histogram of Median Home Value Based on Boston Housing Data",
color=I("black"), fill=I("purple"), xlab="Median Value" ,add=TRUE)
plot4 <- qplot(Boston.Housing$Med.Value, geom="histogram", binwidth=2,
main="Histogram of Median Home Value Based on Boston Housing Data",
color=I("black"), fill=I("purple"), xlab="Median Value" , add=TRUE)