Learn R Programming

seas (version 0.3-3)

mscdata: Meteorological Service of Canada sample climate data

Description

Sample climate data from the Meteorological Service of Canada (MSC) climate stations in western Canada.

Usage

data(mscdata)

Arguments

encoding

latin1

source

Data provided by the Meteorological Service of Canada, with permission. This data may only be reproduced for personal use; any other reproduction is permitted only with the written consent of Environment Canada. http://www.msc.ec.gc.ca/ http://climate.weatheroffice.ec.gc.ca/contacts/

Details

The field id is optional, but very handy when handling multiple stations. Also, the day of year (yday) and year are optional, since these are stored in the date, using dat$date <- as.Date(paste(dat$year,dat$yday),"%Y %j").

The units and long.name attributes stored in the climate variables are optional, but help annotate the graphics.

See Also

mscstn has MSC station ID codes, locations and names; mksub produces subsets of data; read.msc reads MSC archive files, such as A1128551.DLY

Examples

Run this code
data(mscstn)
data(mscdata)
par.orig <- par(no.readonly=TRUE)

# structure in R
str(mscdata)

# first few rows
head(mscdata)

# here are all the station IDs
stnids <- levels(mscdata$id)

# show all data
rng.p <- range(mscdata$precip,na.rm=TRUE)
rng.t <- range(mscdata$t_mean,na.rm=TRUE)
par(mfcol=c(2,3),mgp=c(2,1,0),mar=c(3,3,3,1),bty="l")
for(n in levels(mscdata$id)) {
  dat <- mscdata[mscdata$id==n,]
  plot(t_mean ~ date,dat,"l",col="red",ylim=rng.t)
  abline(h=0)
  plot(precip ~ date,dat,"l",col="blue",ylim=rng.p,
    main=n)
}
par(par.orig)

# show stations and station names available in this data frame
data.frame(stnids, name=getstnname(stnids))
dat <- mksub(mscdata, id=1108447)
dat$month <- mkseas(dat, "mon")
plot(t_mean ~ date, dat, "l")
plot(t_mean ~ date, dat, subset=month=="Dec")
plot.seas.temp(dat)
plot.year(dat)

# plot high-resolution statistics
dly.tmp <- tapply(dat$t_mean,dat$yday,
  quantile,c(5,25,50,75,95)/100,na.rm=TRUE)
dly <- data.frame(yday=1:366,
  t(matrix(unlist(dly.tmp),nrow=5)))
names(dly) <- c("yday","d5","d25","median","d75","d95")
plot(median ~ yday,dly,"n",ylim=c(-5,25),
  ylab="mean temperature",xlab="day of year")
polygon(c(1:366,366:1),c(dly$d5,rev(dly$d95)),border=FALSE,col="grey80")
polygon(c(1:366,366:1),c(dly$d25,rev(dly$d75)),border=FALSE,col="grey50")
lines(median ~ yday,dly)
abline(h=0)

Run the code above in your browser using DataLab