It is important to note that the ggplot function needs to be wrapped in print in order for it to display. Basically I don’t want to waste time writing out “ggplot(df,aes(x=x)) + geom_histogram()” or ”qplot(x,data = df))” for each section’s corresponding column in the df.īelow is the function in it’s entirety: plotHistFunc <- function(x, na.rm = TRUE. The historical results of audits were imported into a data frame with the 8 score columns as well as other instance identifying columns. I usually use the MASS package’s truehist() for quick looks at data, but since I’m writing a detailed loop I will use ggplot2 for fine aesthetic control. I wanted to examine the distribution of section’s scores before and after removing outliers and extreme values. Check out these examples to learn more about for loop: Find the Factorial of a Number. Let’s do the mean example again and get the mean of each element in the list. We can see that x contains 3 even numbers. If you want to do something with the results of the loop, you need more scaffolding. The audit has 8 distinct sections examining the different areas of the plant (shipping, receiving, storage, packaging,etc.) Instead of having one cumulative final score, the audit displays a final score for each section. However, suppose that we want to get mean height by plot: 1 2 3: height.2 <-mean (data Height data Plot 'plot-2'). A client has a specific audit they perform quarterly across 200 of their manufacturing plants.