阿罗哈。我试图在一个图中绘制多个流动持续时间曲线。流动持续时间曲线显示了流动的概率,并具有对数正态y轴和概率标度x轴。我使用示例here来创建曲线。这是我的代码和曲线的截图:
class PrivateAPI;
class Cookie;
class CookieJar {
public:
Cookie getCookie(PrivateAPI);
};
class CookieMonster {
public:
void feed(CookieJar cookieJar);
bool isHungry();
};
class PrivateAPI {};
void CookieMonster::feed(CookieJar cookieJar) {
while (isHungry()) {
cookieJar.getCookie({});
}
}
Click to see my flow-duration curve
我无法在同一图上绘制额外的流量持续时间曲线。我按照其他帖子的建议尝试了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)
}
)
和lines()
,但它们无效。理想情况下,我希望有一个文本文件,其中包含一个流量站号列表和一个带有流量持续时间曲线的图表,用于文本文件中列出的所有流量站点。任何输入都非常感谢。谢谢!
回应Hack-R的评论,这是一个例子。我有一个名为&#34; Input_FDC.txt&#34;的文本文件。带有站号列表。为简单起见,我有4个站号(但实际上,我有30多个站)。以下是文本文件的内容:
站
16071500
16097500
16017000
16068000
points()
代码的一部分是我不知道如何合并到importDVs()
中的部分,以便我可以在一个图中绘制所有4条曲线。如果我要绘制一些曲线,Hack-R建议使用qqmath()
将会起作用。例如,我可以执行以下操作:
qqmath(~ val + val2 ...)
但是有30多条曲线,我正在寻找一种解决方案,允许我循环遍历&#34; Input_FDC.txt&#34;中的电台列表。文件,而不必在代码中包含30多个站点的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
)
。任何输入都非常感谢。谢谢!
答案 0 :(得分:2)
让我们假装我的假val2
数据是您要绘制的另一条曲线:
site.file$val2 <- site.file$val*.5
qqmath(~ val + val2, # 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
)