Inference #2 – put a title above a multiple graph
x is the data y is the main title z is the Y label for the box plot and the X label for the histogram & density plot
eda.shape <- function(x, y, z)
{
par(oma=c(0,0,5,0)) # Add space for main title
par(mfrow = c(2, 2))
hist(x,xlab=z, main="Histogram")
boxplot(x, ylab=z, main="Boxplot")
iqd <- summary(x)[5] - summary(x)[2]
plot(density(x, width = 2 * iqd), xlab = z, ylab = "", type = "l",
+ main = "Density Plot")
qqnorm(x, pch = 1)
qqline(x)
invisible()
mtext(y, side=3, outer=T, cex= 1.2) # Add main title
}
Result
Transcript
Now, we can, of course, get fancier because we can add the label above the histogram saying "Histogram". We can put a label above the boxplot, put a label about the density plot, we can add various text, and set the style.
So now here we have our main title, histogram, box plot, density plot, normal Q-Q plot (which we see we actually had done in our previous plot), but we didn't have the box label. Here in this later version, we now have it saying "Boxplot".