Closed lawinslow closed 9 years ago
Well, using setPDF instead of pdf to open the device would be a great start. I think it's pretty well laid out in the documentation.
On Tue, Mar 31, 2015 at 12:25 PM, Luke Winslow notifications@github.com wrote:
From Lauren: How do we get rid of the warning message
Warning messages: 1: In strwidth(labs, units = "inches", family = "USGS") : font family 'USGS' not found in PostScript font database
Code:
library(USGSwsDataRetrieval) library(USGSwsGraphs) require(lubridate) ############################
Exploratory work on water levels for approving water levels
############################
Import list of sites
You can set the directory below to where you want to work make sure the file of sites that you want to
setwd("C:/Home/")
Change the name of the list file (the example below is GW_lev_list.txt) in the command below. Note the file must be of the format
Agency Code followed by 15 digit STAID there should be no header line in the file
WellList<-read.table('GW_lev_list.txt') # pdf('GW_level_plots.pdf',width=10,height=7) for (i in 1:nrow(WellList)){
If you would like to adjust the period of data that you are plotting you can change the begin.date and end.date
# in the line below. The date entered must be of the format "yyyy-mm-dd' WLdat<-readNWISgwl(WellList[i,2],begin.date='',end.date='') WLdat$dtime<-parse_date_time(paste(as.character(WLdat$lev_dt),as.character(WLdat$lev_tm)),orders=c('ymdhms'),truncated=3) #Note that the y axis is reversed on the plot because the plots are water level depth below land surface this can be changed if altitude needs to be plotted. timePlot(WLdat$dtime,WLdat$lev_va,Plot = list(name = "", what = "points", type = "solid", width = "standard", symbol = "circle", filled = TRUE, size = 0.09, color = "blue"),yaxis.rev=T,xtitle='Date',ytitle='Water Level Below Land Surface Datum',caption=paste('Station',WellList[i,2])) #If you would like to plot a line with the points you can comment out the above line and uncomment out the lines below #timePlot(WLdat$dtime,WLdat$lev_va,Plot = list(name = "", what = "lines", type = "solid", width = "standard", symbol = "circle", filled = TRUE, size = 0.09, color = "blue"),yaxis.rev=T,xtitle='Date',ytitle='Water Level Below Land Surface Datum',caption=paste('Station',WellList[i,2])) #addXY(WLdat$dtime,WLdat$lev_va,Plot = list(name = "", what = "points", type = "solid", width = "standard", symbol = "circle", filled = TRUE, size = 0.09, color = "blue"),yaxis.rev=T)
} dev.off()
— Reply to this email directly or view it on GitHub https://github.com/USGS-R/smwrGraphs/issues/9.
Also, where's the code example coming from? Ideally, we should never see USGSws
packages anymore. USGSwsDataRetrieval -> dataRetrieval and USGSwsGraphs -> smwrGraphs
Hi there - this is Lauren (owner of original question).
I was given this code from someone in the USGS GWUG as a way to pull hydrographs out of GWSI into a PDF for the new ApproveWL process (This is a brief script to plot water levels from NWIS web. The user provides a list of sites as a text file and the provided DiscreteWLplotter.R script reads that data in and plots the data for the period of record).
When I change to setPDF the graphs are made in a window but a PDF is not generated and the graphs disappear. Any advice on updating the code to generate a PDF or if there are new codes using smwrGraphs that I should try instead?
Thank you for your help.
If you could give me 2 example sites, I'll have a look. So, instead of:
WellList<-read.table('GW_lev_list.txt')
Grab the first 2 sites from that file, and paste it in a comment
Thank you.
USGS 314816106325901 USGS 321105106442101
Sorry I took so long to respond. This script worked on my computer:
library(dataRetrieval)
library(smwrGraphs)
library(lubridate)
WellList<-data.frame(agency=c("USGS","USGS"),
site=c("314816106325901","321105106442101"),
stringsAsFactors=FALSE)
setPDF(basename="GW_level_plots",layout="landscape")
for (i in 1:nrow(WellList)){
#If you would like to adjust the period of data that you are plotting you can change the startDate and endDate
# in the line below. The date entered must be of the format "yyyy-mm-dd'
WLdat<-readNWISgwl(WellList[i,2], startDate="", endDate="")
WLdat$dtime<-parse_date_time(paste(WLdat$lev_dt,WLdat$lev_tm),orders=c('ymdhms'),truncated=3)
#Note that the y axis is reversed on the plot because the plots are water level depth below land surface this can be changed if altitude needs to be plotted.
timePlot(WLdat$dtime,WLdat$lev_va,
Plot = list(name = "", what = "points",
type = "solid", width = "standard",
symbol = "circle", filled = TRUE,
size = 0.09, color = "blue"),
yaxis.rev=T,xtitle='Date',
ytitle='Water Level Below Land Surface Datum',
caption=paste('Station',WellList[i,2]))
#If you would like to plot a line with the points you can comment out the above line and uncomment out the lines below
#timePlot(WLdat$dtime,WLdat$lev_va,Plot = list(name = "", what = "lines", type = "solid", width = "standard", symbol = "circle", filled = TRUE, size = 0.09, color = "blue"),yaxis.rev=T,xtitle='Date',ytitle='Water Level Below Land Surface Datum',caption=paste('Station',WellList[i,2]))
#addXY(WLdat$dtime,WLdat$lev_va,Plot = list(name = "", what = "points", type = "solid", width = "standard", symbol = "circle", filled = TRUE, size = 0.09, color = "blue"),yaxis.rev=T)
}
graphics.off()
cat("GW_level_plots.pdf was saved in",getwd())
FYI, we didn't convert the groudwater date/times to a POSIXct directly in the readNWISgwl
function because there seemed to be a lot of non-standard times. Maybe the sites you have are all fine, but there's a chance the line:
WLdat$dtime<-parse_date_time(...
errors out. You could try a tryCatch
there if needed.
Thank you for the updated script. It also ran on my computer successfully. 2 minor issues:
As an alternative to plotting both points and lines with 2 separate calls to timePlot and addXY, you can specify either "both" or "overlap" as the what component in Plot.
On Wed, Apr 1, 2015 at 9:37 AM, lsherson-USGS notifications@github.com wrote:
Thank you for the updated script. It also ran on my computer successfully. 2 minor issues:
1.
For some sites "Calendar Year" and "Date" are both printed on the x-axis. For the sites I gave you this is the case. For other sites (324021107114301, for example) only "Date" is printed. 2.
When I try the timePlot code that is commented out (to get a graph with lines and points) the first line works but when I try to run the second line (to add points) I get the following error. Error in .local(x, y, ...) : unused argument (yaxis.rev = TRUE)
— Reply to this email directly or view it on GitHub https://github.com/USGS-R/smwrGraphs/issues/9#issuecomment-88508311.
Here's what @dlorenz-usgs is saying:
library(dataRetrieval)
library(smwrGraphs)
library(lubridate)
WellList<-data.frame(agency=c("USGS","USGS"),
site=c("314816106325901","321105106442101"),
stringsAsFactors=FALSE)
setPDF(basename="GW_level_plots",layout="landscape")
for (i in 1:nrow(WellList)){
#If you would like to adjust the period of data that you are plotting you can change the startDate and endDate
# in the line below. The date entered must be of the format "yyyy-mm-dd'
WLdat<-readNWISgwl(WellList[i,2], startDate="", endDate="")
WLdat$dtime<-parse_date_time(paste(WLdat$lev_dt,WLdat$lev_tm),
orders=c('ymdhms'),truncated=3)
#Note that the y axis is reversed on the plot because the plots are water level depth below land surface this can be changed if altitude needs to be plotted.
# timePlot(WLdat$dtime,WLdat$lev_va,
# Plot = list(name = "", what = "points",
# type = "solid", width = "standard",
# symbol = "circle", filled = TRUE,
# size = 0.09, color = "blue"),
# yaxis.rev=T,
# ytitle='Water Level Below Land Surface Datum',
# caption=paste('Station',WellList[i,2]))
#
# If you would like to plot a line with the points you can comment
# out the above line and uncomment out the lines below:
timePlot(WLdat$dtime,WLdat$lev_va,
Plot = list(name = "", what = "both",
type = "solid", width = "standard",
symbol = "circle", filled = TRUE,
size = 0.09, color = "blue"),
yaxis.rev=T,
ytitle='Water Level Below Land Surface Datum',
caption=paste('Station',WellList[i,2]))
}
graphics.off()
cat("GW_level_plots.pdf was saved in",getwd())
@dlorenz-usgs : I too got the error she reported when I included the ,yaxis.rev=T
in the addXY
. That makes sense because the yaxis is already set, but I think that was the error she was seeing.
That makes sense, yaxis.rev is not a valid argument for addXY. I just focused on the timePlot call.
On Wed, Apr 1, 2015 at 10:12 AM, Laura DeCicco notifications@github.com wrote:
Here's what @dlorenz-usgs https://github.com/dlorenz-usgs is saying:
library(dataRetrieval) library(smwrGraphs) library(lubridate)WellList<-data.frame(agency=c("USGS","USGS"), site=c("314816106325901","321105106442101"), stringsAsFactors=FALSE)
setPDF(basename="GW_level_plots",layout="landscape")for (i in 1:nrow(WellList)){
If you would like to adjust the period of data that you are plotting you can change the startDate and endDate
in the line below. The date entered must be of the format "yyyy-mm-dd'
WLdat<-readNWISgwl(WellList[i,2], startDate="", endDate="") WLdat$dtime<-parse_date_time(paste(WLdat$lev_dt,WLdat$lev_tm), orders=c('ymdhms'),truncated=3)
Note that the y axis is reversed on the plot because the plots are water level depth below land surface this can be changed if altitude needs to be plotted.# timePlot(WLdat$dtime,WLdat$lev_va,# Plot = list(name = "", what = "points", # type = "solid", width = "standard", # symbol = "circle", filled = TRUE, # size = 0.09, color = "blue"),# yaxis.rev=T,# ytitle='Water Level Below Land Surface Datum',# caption=paste('Station',WellList[i,2]))# # If you would like to plot a line with the points you can comment # out the above line and uncomment out the lines below:
timePlot(WLdat$dtime,WLdat$lev_va, Plot = list(name = "", what = "both", type = "solid", width = "standard", symbol = "circle", filled = TRUE, size = 0.09, color = "blue"), yaxis.rev=T, ytitle='Water Level Below Land Surface Datum', caption=paste('Station',WellList[i,2]))
} graphics.off()
cat("GW_level_plots.pdf was saved in",getwd())
@dlorenz-usgs https://github.com/dlorenz-usgs : I too got the error she reported when I included the ,yaxis.rev=T in the addXY. That makes sense because the yaxis is already set, but I think that was the error she was seeing.
— Reply to this email directly or view it on GitHub https://github.com/USGS-R/smwrGraphs/issues/9#issuecomment-88519367.
Thank you for your help. The "both" function you recommended worked and the script is running smoothly now.
@dlorenz-usgs But why is yaxis.rev
in the documentation for addXY then?
It is not as an argument to addXY. It is noted as a component of the current argument to addXY.
On Wed, Apr 1, 2015 at 11:03 AM, Luke Winslow notifications@github.com wrote:
But why is yaxis.rev in the documentation for addXY then?
— Reply to this email directly or view it on GitHub https://github.com/USGS-R/smwrGraphs/issues/9#issuecomment-88534105.
Ah, I see, it's being passed in to a parameter in list.
From Lauren: How do we get rid of the warning message
Code: