[R] Plot two values on same axes

David Winsemius dw|n@em|u@ @end|ng |rom comc@@t@net
Fri Sep 27 01:08:58 CEST 2019


Instead of trying to mix lattice and base functions, you might try using the formula:

maxtemp+mintemp ~ sampdate

And then: col= c(“red”, “blue”)

Sent from my iPhone, so make sure those quotes are ordinary double quotes. 

— 
David


> On Sep 27, 2019, at 6:27 AM, Rich Shepard <rshepard using appl-ecosys.com> wrote:
> 
> 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
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list