Welcome, Guest
Username: Password: Remember me

TOPIC: POTM-01 (May): First plot of the month!

POTM-01 (May): First plot of the month! 1 year 2 months ago #15

  • Marcus Beck
  • Offline
  • Administrator
  • Posts: 32
  • Thank you received: 5
  • Karma: 4
Welcome to the first post for our 'plot of the month' category! These posts will feature code snippets that can be used to reproduce plots or maps of SWMP data. Ideally, each post should have a reproducible example that includes code to access data and to produce the plot using R. These requirements should be easy to address with the tools provided by SWMPr, although we don't want to discourage users from posting content if the requirements can't be met. Therefore, we encourage posts on anything related to the visualization of SWMP data, with the understanding that reproducible code is a desired but not required part of each post.

Plot images can be uploaded and embedded in each post as jpeg attachments. Code snippets can also be shown using the code tags from the menu above.

On to the fun stuff... This post describes how you can create a summary plot of a SWMP data variable using functions in the SWMPr package. Check out the SWMPr tab on this website for more information about this package. The code below imports station data using the import_remote function and creates the plot using the plot_summary function. You'll notice that the plot is identical those on the SWMP summary widget and these functions were in fact used to create the application.

Start by installing and loading the SWMPr package in R.
install.packages('SWMPr')
library(SWMPr)

Import site data for the plot, run qaqc filters.
dat <- import_remote('apadbwq')
dat <- qaqc(dat)

Create a summary plot for water temperature.
plot_summary(dat, param = 'temp')

And the plot...


Different parameters can be plotted by changing the param argument. The date ranges can also be changed with the years argument. More information about the plot_summary command can be found in the help file from the package. Just run ?plot_summary to see the file.

Cheers,

Marcus
Last Edit: 10 months 3 weeks ago by Todd.OBrien. Reason: Standardizing Titles
The administrator has disabled public write access.

First plot of the month! 1 year 1 month ago #16

This is awesome, Marcus!

I decided to play with some chlorophyll data. Since I just uploaded 2014 data to the CDMO last week and wanted it included, I downloaded the data myself and used import_local rather than import_remote.

I had to prep the file - there were 3 header lines, and I had to delete the top 2. (There's also a lot of text below all the data, which I forgot to delete, and that didn't turn out to be a problem - hooray!)

Another thing I had to do to prep my file was change the file name from all caps to lower case - when I got the file from the CDMO, it was named 'GNDPCNUT' and I had to change it to 'gndpcnut'.

So here's my code:
#install SWMPr (commented out b/c only need to do it once)
#install.packages('SWMPr')
#load SWMPr
library(SWMPr)
#import and qc data from the site you want
path <- ('C:/Users/kimberly.cressman/Desktop/graphs from R')
dat <- import_local(path, 'gndpcnut')
dat <- qaqc(dat, qaqc_keep = c(0, 1, 4))
#create summmary plot for chlorophyll a
plot_summary(dat, param = 'chla_n')


And the plot:



ETA - another difference in my code is that I wanted to hold on to more than just 0 QC flags; 4 is a historical flag that's equivalent to 0. I also kept suspect data, flagged as 1. So in the help file I saw that qaqc_keep portion of the qaqc step and it worked out!
Last Edit: 1 year 1 month ago by Kim_Cressman.
The administrator has disabled public write access.

First plot of the month! 1 year 1 month ago #17

  • Marcus Beck
  • Offline
  • Administrator
  • Posts: 32
  • Thank you received: 5
  • Karma: 4
Nice Kim, and yes, the help file is your friend!

I just made some changes to the import_local function to handle upper and lower case file inputs... this is only in the development version, but will be on CRAN eventually.

-Marcus
The administrator has disabled public write access.
Time to create page: 0.084 seconds
Powered by Kunena Forum