by Joseph Rickert
The weather is on everybody's mind these days: too much ice and snow east of the Rockies and no rain to speak fo in California. Ram Narasimhan has made it a little easier for R users to keep track of what's going on and also get a historical perspective. His new R package weatherData makes it easy to down load weather data from various stations around the world collecting data. Here is a time series plot of the average temperature recorded at SFO last year with the help of the weatherData's getWeatherForYear() function. It is really nice that the function returns a data frame of hourly data with the Time variable as class POSIXct.
### Some Code to Get Average Temperature at SFO # JB Rickert library(weatherData) library(ggplot2) library(scales) library(plyr) w2013 <- getWeatherForYear("sfo",2013) w2013$shortdate <- strftime(w2013$Time, format="%m-%d") meanTemp <- ddply(w2013, .(shortdate), summarize, mean_T=mean(TemperatureF)) meanTemp$shortdate <- as.Date(meanTemp$shortdate,format="%m-%d") ggplot(meanTemp, aes(shortdate, mean_T)) + geom_line() + scale_x_date(labels=date_format("%m/%d")) + xlab("") + ylab("Mean Temp deg F") + ggtitle("2013 Average Daily Temperature at SFO")