[R] Plot two values on same axes
Rich Shepard
r@hep@rd @end|ng |rom @pp|-eco@y@@com
Fri Sep 27 00:27:49 CEST 2019
I want to plot maximum and minimum water temperatures on the same axes and
thought I had the correct syntax:
watertemp <- read.table("../../data/hydro/water-temp.dat", header = TRUE, sep =",")
watertemp$sampdate <- as.Date(as.character(watertemp$sampdate))
watertempsum <- summary(watertemp)
print(watertempsum)
maxwatemp <- xyplot(maxtemp ~ sampdate, data=watertemp, col="red", type="h", main="USGS Foss Gauge Water Temperatures, 1974-1981", ylab="Temperature (C)", xlab="Date", scales=list(tck=c(1,0)))
minwatemp <- xyplot(mintemp ~ sampdate, data=watertemp, col="blue", type="h")
plot(maxwatemp)
par(new=TRUE)
plot(minwatemp)
However, R plots only minwatemp and displays this:
Warning message:
In par(new = TRUE) : calling par(new=TRUE) with no plot
Despite my searching for the reason I don't see what syntax error I made.
The two questions I ask of you:
1. Where have I gone wrong in this script?
2. With 2,492 daily observations in the source file (including 242 NAs for
maxtemp and 243 NAs for mintemp), what would be a more appropriate plot to
show both sets of data?
Thanks in advance,
Rich
More information about the R-help
mailing list