I am using the qcc package. I am running a simple process.capability plot inside of a loop for multiple materials. As it loops through the columns, the title of the plot is always the df.1[i], rather than the column name.
process.capability(qcc(df.1[i], type="xbar.one"), nsigmas = 3, spec.limits = c(NA, 20), add.stats = T)
Or conversely, is it possible to use the actual column name while still in the loop?
process.capability(qcc(df.1$Aluminum, type="xbar.one"), nsigmas = 3, spec.limits = c(NA, 20), add.stats = T)
Full loop below:
for (i in 5:length(colnames(df.1))){
df.2 <- df.1 %>%
rename(test_metal = colnames(df.1[i]))
test_group = with(df.2, qcc.groups(test_metal, batch_num))
png("test_plot.png")
q1 <- qcc(test_group, type = "xbar.one", nsigmas = 3, chart.all = F, ylim = c(0, max(df.1$Aluminum)), title = paste(colnames(df.1)[i]))
dev.off()
}
You can use a combination of
eval
andsubstitute
to have the call for process.capability in the correct form. I used an example from the qcc package:Brief explanation, first you use substitute to replace "X" with the colname you want to plot. Then this remains an expression and you have to use eval on it, together with the data.frame df.1. (something like "with" you used before)