weatherData is a collection of functions that will fetch weather (Temperature, Pressure, Humidity etc.) data from the Web for you as clean data frame.
- About the Package
- Installing weatherData Package
- Basic Usage: Quick start
- Typical Workflow
- Detailed Examples
- Frequently Asked Questions
- Built-in Datasets
- Demo Shiny Application
- Articles about the package
If you want to perform weather Analysis, but don't wish to do the data scraping yourself, you can consider using
weatherData. Given a few parameters, it has functions that return the available data in a time-stamped data frame that is easy to work with.
You can install the version from CRAN, or you can try out the version hosted in Github. Github has the newer version, which is in development. This is where I try out the newer functions.
Install and Load the library
The latest version of weatherData is on Github. (Note that this is the development version, and is usually ahead of what's on CRAN.) To install the development version of weatherData from github, use the
install.packages("devtools") library("devtools") install_github("Ram-N/weatherData")
Once the package has installed, load the library
Note: Windows users must also first install Rtools.
If you want to get started using the functions in the package right away, you can do so.
Quickstart Example 1. Start by getting the temperature data for a Location of interest for a particular date.
Quickstart Example 1a. If you want detailed data (meaning, more columns besides Temperature):
getWeatherForDate("SEA", "2014-05-05", opt_detailed=TRUE)
Quickstart Example 1b. If you want detailed data for a range of dates instead of for a single date, just specify a start date and end date:
getWeatherForDate("SEA", "2014-04-01", end_date="2014-04-30") #This will fetch a dataframe of temperature data for the month of April.
Quickstart Example 2. Just get me everything for a whole year for a Location of interest.
dfw_wx <- getWeatherForYear("DFW", 2013)
This is a just a very small sample of the functions. There are also a number of 'helper functions' to make life a little easier.
Typically, in order to analyze the available weather data, you will need to decide on four parameters:
- Location. (Which city, zipcode or weather station are you interested in)
- Time Interval (Is this for 1 day, a sequence of dates, or a whole year or more)
- Level of Detail: Is one record per day adequate? (If so, use summarized) If not, specify the
- Which of the available columns are you interested in? (Temperature, Pressure, Wind, Humidity or all the available ones.)
In all the examples, it is assumed that you have loaded the library. You can do so by typing
station id for the location(s) that you are interested in. If you know the airport code (3 letters) you can try that.
Once you have the
station_id and the date ranges, it is a simple matter to fetch the data.
A few Details around finding the weather station ID's can be found here
Set the date range:
end_date="YYYY-MM-DD" If you need data for just one day, then end_date doesn't have to be specified.
If the default level of detail is sufficient, call one of the
getWeatherData() functions, and assign the data frame being returned to it.
wx_df <- getWeatherForDate("SAN", "2011-08-26")
- Example 1: Using
getWeatherForYear()to compare the daily temperature differences for two cities. In this example, we get one year's worth of data for two cities, and plot the daily differences
- Example 2: Getting Wind Data for a City: This example illustrates how we go about getting Wind data for a city of our choosing.
- Example 3: Comparing Intra-day Humidity: This example illustrates how we go about getting one day's worth of custom data for several South East Asian cities, and how to plot the time series data obtained.
- Example 4: Getting Data from Personal Weather Stations: This simple example illustrates how to go about getting data from a personal weather station (as opposed to from an Airport.)
- If you are running into difficulties, some of the answers to FAQ might be of some help.
The package comes with a few pre-loaded datasets and those are available for trying out some basic analysis right away. More details about what is included and what each of those datasets contains can be found here. That page also includes some sample code for using one of the datasets,
WeatherCompare is a Shiny App that uses the data brought over by weatherData and then summarized in various ways.
There have been a few articles written about the functions in this package. They might be useful to get a feel for use cases.
Joe Rickert of
Revolution Analytics has written a blog post with a sample script that uses
weatherData. Do check it out.
Angela Hey, a tech blogger for the Mountain View Voice wrote an article about analyzing data with R, and used weatherData functions for her examples.
weatherData package has benefited immensely from the suggestions of quite a number of weather analysts. Their feedback, suggestions
and bug reports have helped immensely. Detailed credits for their contributions can be found here.