I have a chemical dataset with 6 variables: Oxygen, Nitrogen, Sodium, Calcium, Zinc, and Copper. I generated a matrix plot that has the the histogram of each variable and the corresponding qq plot with title of each plot as the variable's name. Below is my code, it's working, but it's inefficient because I did a lot of copy/paste. Is there a way to automate a process to generate plots for every variable in the dataset where every plot has the name of the variable as a title? Also, as you see in the code I am using mfrow in R-studio which limits the number of plots- It says margins are too large. Is there a way to send the output directly to a pdf without visualizing it in R-studio just to avoid the issue with margin too large? I just started learning R. Excuse me if my question is too basic. Thank you!
par(mfrow=c(6,2))
hist(Oxygen,main="Oxygen")
qqnorm(Oxygen,main="Oxygen");qqline(Oxygen, col='red')
hist(Nitrogen,main="Nitrogen")
qqnorm(Nitrogen,main="Nitrogen");qqline(Nitrogen, col='red')
hist(Sodium,main="Sodium")
qqnorm(Sodium,main="Sodium");qqline(Sodium, col='red')
hist(Calcium,main="Calcium")
qqnorm(Calcium,main="Calcium");qqline(Calcium, col='red')
hist(Zinc,main="Zinc")
qqnorm(Zinc,main="Zinc");qqline(Zinc, col='red')
hist(Copper,main="Copper")
qqnorm(Copper,main="Copper");qqline(Copper, col='red')