When plotting in a loop in r, how do you call a variable that is not one of the plot variables (x or y)?
My dataset has the following fields: Level (y-value), CG(x-value), CatNum, and CatName. CatNum is the category number, and CatName is the corresponding name.
I have successfully created a box plot loop to make one plot for each unique CatNum. I want both CatNum and CatName to appear in the plot title, but have only been able to include CatNum. My attempt is below, but when I call the variable "name", it prints the entire CatName column, over top of the plot.
How do I call both CatNum and CatName for the current "cat" in the loop, so that the title will be "Category (CatNum) (CatName)"?
for (cat in unique(dataset$Category)){
#d <- subset(dataset, Category==cat)
name <- dataset$CatName
boxplot(Level[Category==cat]~CG[Category==cat], data=dataset, xlab=" Group",
ylab="Level", main=paste("Category", CatNum, CatName), outline=FALSE)
}