Skip to content
Prev 305961 / 398506 Next

Line over Boxplot

Hello,

Works with me after correcting your lines() instruction. Your code 
doesn't say what columns to use as coordinates, just where to look for them.
Also, (1) allways explicitly close the device using dev.off(). (2) The 
grid lines were over the boxes. A way to avoid this is to plot the 
boxes, then the grid, then replot the boxes with the parameter add = 
TRUE (There's a function ?grid). And (3) you don't need the call to 
par(new=TRUE), abline() doesn't restart the graphics device.
The full code follows.


url1 <- "http://r.789695.n4.nabble.com/file/n4643736/tmax.final.text"
url2 <- "http://r.789695.n4.nabble.com/file/n4643736/temp.final.text"

pdf(file="boxplot_tmax_$YYYY$MM$DD${HH}.pdf", height=10, width=12)

soton.df = read.table(url1, header=TRUE)
gfs.df = read.table(url2, header=TRUE)

boxplot (TMAX ~ HOUR, data=soton.df,
     xlab="Forecast Hour", ylab="MAX TEMP",
     main="GEFS $YYYY$MM$DD ${HH}Z FORECAST MAX TEMPS",
     whiskcol="red", col="red", outline=TRUE,
     ylim=c(0, 100), xlim=c(1, 30),
     xaxs="i", yaxs="i")

abline(h=seq(0, 100,by=5), lty=2)
abline(v=seq(1, 30, by=1), lty=2)

boxplot (TMAX ~ HOUR, data=soton.df,
     xlab="Forecast Hour", ylab="MAX TEMP",
     main="GEFS $YYYY$MM$DD ${HH}Z FORECAST MAX TEMPS",
     whiskcol="red", col="red", outline=TRUE,
     ylim=c(0, 100),xlim=c(1, 30),
     xaxs="i", yaxs="i",
     add = TRUE)
lines(TMAX ~ HOUR, data=gfs.df, type="o", col="green")

dev.off()

Hope this helps,

Rui Barradas
Em 20-09-2012 14:41, gfishel escreveu: