I am attempting to tell R to run multiple lines at a time using "{ }" brackets. I have done this with success before. I am attempting to generate multiple plots at a time by defining several plots in one function.
for example:
qqnorm(residuals(LM_auto), col="black", fg="blue", pch= 21, bg=col_1, alpha = .7, sub = shapiro_output, xlab = "Shapiro Results Below:")+qqline(residuals(LM_auto))
plot(density(residuals(LM_auto)), col="black", fg="blue", bg=col_1) + polygon(density(residuals(LM_auto)), col=col_1)+
plot(residuals(LM_auto)~fitted(LM_auto), col="black", fg="blue", pch= 21, bg=col_1, alpha = .7, main="Summary Output-------------->")+
abline(h = c(100, 10, 2, 0, -2, -10, -100), col = c("yellow", "orange", "blue", "black", "blue", "orange", "yellow"), lty = c(5,4,2,1,2,4,5))+
plot(residuals(LM_auto)~xparameter, xlab=X_variable_title, col=col_1, fg="blue", pch= 21, bg=col_1, alpha = .7, main=summary_output, cex.main=.6)+
abline(h = c(100, 10, 2, 0, -2, -10, -100), col = c("yellow", "orange", "blue", "black", "blue", "orange", "yellow"), lty = c(5,4,2,1,2,4,5))'
All of these lines work, even when highlighted and run as a block. However, if I attempt to put them into brackets, or define the block as a function, they will not run (aside from generating the qqplot), and R returns a set of errors.
{
qqnorm(residuals(LM_auto), col="black", fg="blue", pch= 21, bg=col_1, alpha = .7, sub = shapiro_output, xlab = "Shapiro Results Below:")+qqline(residuals(LM_auto))
plot(density(residuals(LM_auto)), col="black", fg="blue", bg=col_1) + polygon(density(residuals(LM_auto)), col=col_1)+
plot(residuals(LM_auto)~fitted(LM_auto), col="black", fg="blue", pch= 21, bg=col_1, alpha = .7, main="Summary Output-------------->")+
abline(h = c(100, 10, 2, 0, -2, -10, -100), col = c("yellow", "orange", "blue", "black", "blue", "orange", "yellow"), lty = c(5,4,2,1,2,4,5))+
plot(residuals(LM_auto)~xparameter, xlab=X_variable_title, col=col_1, fg="blue", pch= 21, bg=col_1, alpha = .7, main=summary_output, cex.main=.6)+
abline(h = c(100, 10, 2, 0, -2, -10, -100), col = c("yellow", "orange", "blue", "black", "blue", "orange", "yellow"), lty = c(5,4,2,1,2,4,5))
}
errors:
Error in qqnorm(residuals(LM_auto), col = "black", fg = "blue", pch = as.numeric(21), :
non-numeric argument to binary operator
In addition: Warning messages:
1: In plot.window(...) : "alpha" is not a graphical parameter
2: In plot.xy(xy, type, ...) : "alpha" is not a graphical parameter
3: In axis(side = side, at = at, labels = labels, ...) : "alpha" is not a graphical parameter
4: In axis(side = side, at = at, labels = labels, ...) : "alpha" is not a graphical parameter
5: In box(...) : "alpha" is not a graphical parameter
6: In title(...) : "alpha" is not a graphical parameter'
It seems to be an error with the qqnorm function, as I can run my code within brackets as long as that line is removed.
Why is 21 not recognized as numeric? Or is that really the issue? I have tried it with:
pch=as.numeric(21)
But this still does not work.
Why can't R properly read this all together as a function when it can do so as a highlighted block?
Any help would be much appreciated, -Thanks.