Plotting BP Oil Spill Testing Data using R

June 10, 2010
By

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


The Deepwater Horizon Incident is in the U.S. headlines and on many peoples minds. The folks over at Revolution Analytics were even discussing this subject today. Several government sites including the NOAA have sections dedicated to the problem. In fact, the EPA is concerned enough that they are eliciting technical solutions right on the site. In the "other" category they include a section on Data Collection and Management. So if you have any good ideas...

The following is a simple demonstration of how to retrieve the data related to water sampling from the EPA web site and to a quick survey of the data using R. The data is available from the Environmental Protection Agency in csv format. We start by reading this comma delimited data in:

data=read.table('http://www.epa.gov/bpspill/data/water_sampling_update.csv', header=TRUE, skip=1,sep=",")

The current version of the report reports no immediate concern (quite literally - NA is returned):

unique(data$LEVEL.OF.CONCERN)


The dates being tested in the current report are for a five day range (5/29/2010 - 6/2/2010).

sort(unique(data$DATE))




A list of the substances being tested for results in the following:

2-Methylnaphthalene
Acenaphthene
Acenaphthylene
Anthracene
Benzene
Benzo(a)anthracene
Benzo(a)pyrene
Benzo(b)fluoranthene
Benzo(g,h,i)perylene
Benzo(k)fluoranthene
Chrysene
Dibenzo(a,h)anthracene
Ethylbenzene
Fluoranthene
Fluorene
Indeno(1,2,3-cd)pyrene
Naphthalene
Nickel
Phenanthrene
Pyrene
Toluene
Vanadium
Xylene (total)
sort(unique(data$SUBSTANCE))

Testing location (latitude and longitude) are also included in the data set. Using the maps R package, we can plot these locations on a map of Louisiana and create the image presented above.

library(maps)
map("state", "louisiana", plot = TRUE, fill=TRUE, col='white')
points(x=data$LONGITUDE, y=data$LATITUDE, col='red',cex=0.75)
map.axes()
map.scale()

A close up of the area can also be obtained using the xlim and ylim parameters.
# Closeup
map("state", "louisiana", plot = TRUE, fill=TRUE, col='white',xlim=range(x$LONGITUDE), ylim=range(x$LATITUDE))
points(x=x$LONGITUDE, y=x$LATITUDE, col='red',cex=0.75)
map.axes()
map.scale()

Although this is not a particularly deep analysis, it shows the relative ease by which data can be obtained and analyzed and visualized using R.

To leave a comment for the author, please follow the link and comment on his blog: R-Chart.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: 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...

Tags: , , ,

Comments are closed.