



However, we can string together ggplot commands in a list for easy re-use. Y-axis labels need to be shown at 0 and at the upper scaleĪdd breaks and limits to scale_y_continuousĪdd the number of observations above each boxplotĬhange font (we'll use "serif" in this post, although that is not the official USGS font)Īs you can see, it will not be as simple as creating a single custom ggplot theme to comply with the requirements. Tick marks should be on both sides of the y axis The approving officer would probably come back from the review with the following comments: Reviewer's CommentsĪdd horizontal bars to the upper and lower whiskers

However, for an official USGS report, USGS employees need to get the graphics approved to assure they follow specific style guidelines. Is that graph great? YES! And for presentations and/or journal publications, that graph might be appropriate. # Create basic ggplot graph: ggplot(data = chloride,Īes(x = month, y = result_va)) + geom_boxplot() + xlab( "Month") + ylab(cl_name) + labs(title = cl_site) # Pull out the official parameter and site names for labels:Ĭl_name <- attr(chloride, "variableInfo")]Ĭl_site <- attr(chloride, "siteInfo")] We’ll use the package dataRetrieval to get the data (see this tutorial for more information on dataRetrieval), and plot a simple boxplot by month using ggplot2:Ĭhloride <- readNWISqw( "04085139", "00940")Ĭhloride $month <- month.abb Ĭhloride $month <- factor(chloride $month, levels = month.abb) Here we’ll use chloride data (parameter code “00940”) measured at a USGS station on the Fox River in Green Bay, WI (station ID “04085139”). Features in this post take advantage of enhancements to ggplot2 in version 3.0.0 or later.įirst, let’s get some data that might be typically plotted in a USGS report using a boxplot. Some additional goals here are to create boxplots that come close to USGS style. Therefore, this post breaks down the calculations into (hopefully!) easy-to-follow chunks of code for you to make your own box plot legend if necessary. The help file for this function is very informative, but it’s often non-R users asking what exactly the plot means. The base R function to calculate the box plot limits is boxplot.stats. A question that comes up is what exactly do the box plots represent? The ggplot2 box plots follow standard Tukey representations, and there are many references of this online and in standard statistical text books. Exploring ggplot2 boxplots - Defining limits and adjusting style AugLaura DeCiccoīoxplots are often used to show data distributions, and ggplot2 is often used to visualize data.
