Chris Li wrote:
Thanks for the reply guys. Below are the script and data files.

http://www.nabble.com/file/p24734049/HEAD_calibration.R HEAD_calibration.R http://www.nabble.com/file/p24734049/6527-1052 6527-1052 http://www.nabble.com/file/p24734049/6527-1054 6527-1054 http://www.nabble.com/file/p24734049/MAR3 MAR3
Once again, thank you for your help, greatly appreciated!!

Chris


Chris Li wrote:
Hi everyone. I am new to R.

It will be greatly appreciated if someone can help me with the following
questions.

Here's the graph I have just produced. http://www.nabble.com/file/p24732839/calibration.jpeg
(1) How can I put the legend on top of the grid lines?

(2) How can I match the grid lines with the x-axis ticks?

(3) How can I change the x-axis format from e.g. Mar, Apr...etc to
1-3-2009,1-4-2009...etc?

Many thanks! :-)

Chris




Example for your loop:

for (i in c(1:n)){
    file.name=f[i]
    dat<-read.csv(file.name,header=F)
    colnames(dat)<-c("obsTime","obsHead","comTime","comHead")
    obsTime<-as.Date(dat$obsTime,origin=model.startdate)
    comTime<-as.Date(dat$comTime,origin=model.startdate)

### omit x axis at first:
plot(obsTime,dat$obsHead,main=file.name,xlab="Date",ylab="Hydraulic Head (mAHD)",col="blue",ylim=c(ymin,ymax), xaxt="n")

### add x axis with given format and save the locations:first:
    xticks <- axis.Date(1, obsTime, format = "%d-%m-%Y")
    lines(comTime,dat$comHead,col="red")

### add you self designed grid:
    abline(v=xticks, h=axTicks(2), lty=1, col="darkgray")

### legend with white background at the end:
legend("bottomright",legend=c("Observed Head","Computed Head"),col=c("blue","red"),lty=c(0,1),pch=c(1,-1), bg="white")


### forget about:
#    grid(lty=1,col="darkgray")
}



Uwe Ligges

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to