[R] Superscripts and rounding

ehux emily.huxter at ec.gc.ca
Wed Jul 29 21:57:36 CEST 2009


library(RODBC)
library(HYDAT)
You will need to install HYDAT (the zip file) from
http://www.geog.ubc.ca/~rdmoore/Rcode.htm 

Below is my current code - which works. The [[]] is the way i am accessing
the columns from the data frame. 

thanks again for all your help!!!!

# load HYDAT data
par(mfrow=c(3,1))
path <- 'c:\\HYDAT'
wsc.id <- '11AB075'
stn <- ReadHydatFile(path, wsc.id)      #if data in CDROM image
# stn <- ReadHydatDatabase (path, wsc.id) #if data in database

# subset daily flow record for plotting purposes
dates <- c(as.Date('1927-01-01'), as.Date('1960-12-31'))
decade <- subset(stn[['flow']][['daily']], date >= dates[1] & date <=
dates[2])

# identify days flagged as backwater ('B') or estimated ('E')
# daily.flags is a vector of color names used to apply to points
daily.flags <- rep('NA', nrow(decade))
daily.flags[which(decade[['flag']] == 'A')] <- 'goldenrod'
daily.flags[which(decade[['flag']] == 'E')] <- 'red'
daily.flags[which(decade[['flag']] == 'B')] <- 'blue' 

 # subset daily flow record for plotting purposes
dates <- c(as.Date('1970-01-01'), as.Date('2008-12-31'))
decade <- subset(stn[['flow']][['daily']], date >= dates[1] & date <=
dates[2])

# identify days flagged as backwater ('B') or estimated ('E')
# daily.flags is a vector of color names used to apply to points
daily.flags <- rep('NA', nrow(decade))
daily.flags[which(decade[['flag']] == 'A')] <- 'goldenrod'
daily.flags[which(decade[['flag']] == 'E')] <- 'red'
daily.flags[which(decade[['flag']] == 'B')] <- 'blue'

  # last plot entire series with subtitle as a light gray line

plot (
  decade[['date']],
  decade[['value']],

  type = 'l',
  col = 'lightsteelblue4',
  ylab = 'Discharge [cms]',
  main = sprintf('%s [%s]', stn[['metadata']][['name']],
stn[['metadata']][['id']]),
  sub = sprintf('Seasonal station with natural streamflow - Lat: %s Lon: %s
        Gross Area %s\km\UB2 - Effective Area %s\km\UB2',
stn[['metadata']][['latitude']],
        stn[['metadata']][['longitude']],stn[['metadata']][['grossarea']],
        stn[['metadata']][['effectivearea']],
  cex.sub = 1, font.sub = 3, col.sub = "black"
  ))


# overlay the points where the daily value has been flagged.
# Note the daily.flags array contains NAs for days when not flagged, so
these will not show up as
# points in the plot.
lines (
  decade[['date']],
  decade[['value']],
  type = 'p',
  cex = 0.1,
  pch = 20,
  col = daily.flags
)

# slap a legend on the plot...
legend (
  x = 'topright',
  legend = c('Partial', 'Estimated', 'Backwater', 'Not flagged (A, E or
B)'),
  lty = c(0,0,0,1),
  pch = c(20,20,20,NA),
  col = c('goldenrod','red','blue','lightsteelblue4'),
  cex = 0.75
)
-- 
View this message in context: http://www.nabble.com/Superscripts-and-rounding-tp24682319p24726439.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list