【发布时间】:2016-08-10 00:40:42
【问题描述】:
阿罗哈。我试图在一个图中绘制多条流动持续时间曲线。流量持续时间曲线显示流量的概率,并具有对数正态 y 轴和概率标度 x 轴。我使用示例here 创建曲线。这是我的代码和曲线截图:
library(waterData)
library(lattice)
library(latticeExtra)
site.no <- "16068000" # streamflow station number
site.file <- importDVs(site.no, code = "00060", stat = "00003") # reads data from NWIS
PrbGrd <- qnorm(c(.001, .01, .10, .30, .50, .70, .90, .99, .999)) # create probablity scale lines
PrbGrdL<-c("99.9", "99", "90", "70", "50", "30", "10", "1", "0.1") # exceedence probability scale labels
ValGrd<-c(seq(0.001,0.01,0.001),seq(0.01,0.1,0.01),seq(0.1,1,0.1),seq(1,10,1),seq(10,100,10)) # create value grid lines
ValGrd<-log10(ValGrd) # convert value grid lines to log
qqmath(~ val, # val = data column with streamflow data
data = site.file,
distribution = function(p) qnorm(p),
main = "Flow-duration curves for streamgages on Kauai",
pch = 20,
cex = 0.5,
xlab = "Percentage of time discharge was equaled or exceeded (%)",
ylab = "Daily mean discharge, in cubic feet per second",
xlim = c(max(PrbGrd),min(PrbGrd)),
scales = list(y=list(log=10,alternating=1),x = list(at = PrbGrd, labels = PrbGrdL, cex = 0.8)),
yscale.components=yscale.components.log10ticks,
panel = function(x,...){
panel.abline(v=PrbGrd ,col="grey",lty=3)
panel.abline(h=ValGrd,col="grey",lty=3)
panel.qqmath(x,distribution=qnorm)
}
)
Click to see my flow-duration curve
我无法在同一图上绘制额外的流动持续时间曲线。我按照其他帖子中的建议尝试了lines() 和points(),但它们不起作用。理想情况下,我想要一个包含流量站编号列表的文本文件和一个带有文本文件中列出的所有流量站的流量持续时间曲线的图。非常感谢任何输入。谢谢!
针对 Hack-R 的评论,这里有一个例子。我有一个名为“Input_FDC.txt”的文本文件,其中包含站号列表。为简单起见,我有 4 个站号(但实际上,我有 30 多个站)。以下是文本文件的内容:
车站
16071500
16097500
16017000
16068000
带有importDVs() 的代码部分是我不知道如何合并到qqmath() 中的部分,以便我可以在一个图中绘制所有4 条曲线。如果我要绘制几条曲线,Hack-R 建议使用qqmath(~ val + val2 ...) 将起作用。例如,我可以执行以下操作:
input.file <- "Input_FDC.txt" # text file with list of station numbers
path.R <- "C:/Users/ccheng/Documents/R/" # enter directory of text file
stn.file <- read.delim(paste(path.R, input.file, sep = ""), header = TRUE)
site.no <- as.character(stn.file$Stations) # for importDVs to work, station no. needs to be in quotes
for(i in 1:length(site.no)) {
x.1 <- importDVs(site.no[i], code = "00060", stat = "00003")
assign(paste("flow",i,sep=""), x.1$val)
}
PrbGrd <- qnorm(c(.001, .01, .10, .30, .50, .70, .90, .99, .999)) # create probablity scale lines
PrbGrdL<-c("99.9", "99", "90", "70", "50", "30", "10", "1", "0.1") # exceedence probability scale labels
ValGrd<-c(seq(0.001,0.01,0.001),seq(0.01,0.1,0.01),seq(0.1,1,0.1),seq(1,10,1),seq(10,100,10)) # create value grid lines
ValGrd<-log10(ValGrd) # convert value grid lines to log
qqmath(~ flow1 + flow2 + flow3 + flow4,
distribution = function(p) qnorm(p),
main = "Flow-duration curves for streamgages on Kauai",
auto.key = list(points = F, lines = T, text = site.no, columns = 4),
pch = 20,
cex = 0.5,
xlab = "Percentage of time discharge was equaled or exceeded (%)",
ylab = "Daily mean discharge, in cubic feet per second",
xlim = c(max(PrbGrd),min(PrbGrd)),
scales = list(y=list(log=10,alternating=1),x = list(at = PrbGrd, labels = PrbGrdL, cex = 0.8)),
yscale.components=yscale.components.log10ticks
)
但是对于 30 多条曲线,我正在寻找一种解决方案,该解决方案允许我循环浏览“Input_FDC.txt”文件中的站点列表,而不必在代码中包含 30 多个站点的 ~ flow1 + flow2 + ... flow30。非常感谢任何输入。谢谢!
【问题讨论】:
-
对不起,“site.no.1”应该是“site.no”。我会更正代码。
-
仅供参考:
lines()和points()(甚至add=T)不起作用的原因是qqmath()使用lattice包进行绘图,该包不允许像这样的新层. -
@Vincent 感谢您的澄清。