R and the Weather

February 6, 2014

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

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
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")

To leave a comment for the author, please follow the link and comment on their blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)