I have a for loop to create box plots for a couple dozen analytes grouped by location:
for(parameter in analyte_list) {
print(parameter)
df_analytes <- df %>% filter(Analyte == parameter)
df_box <- ggplot(df_analytes, aes(y = Result, x = MONTH, fill = Location)) +
geom_boxplot() +
ylab(paste(unique(df_analytes$Units))) +
xlab("Month") +
ggtitle(paste("Monthly", parameter))
ggsave(paste0("Plots/Box/Box_", parameter, ".png"), df_box)
print(df_box)
}
Which produces boxplots that look like this: WaterTemp and Cl
The first plot looks fine as is but the second is difficult to read due to a single high outlier. Is there a way to define ylim automatically (perhaps according to the stats for each analyte or some determined value based on the 75th percentile) for better visualization without having to remove outliers?