Site icon R-bloggers

Visualization of AQI

[This article was first published on Chen-ang Statistics » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The day before yesterday is spring festival which is one of the most famous Chinese festivals, and setting off firecrackers outside on New Year Eve is a traditional custom. However, firecrackers will pollute circumstance severely and cause the hazy weather. Of course the pollution of different province is not the same, and through charts we can view the pollution distribution directly. We use the AQI(Air Quality Index) to measure the air pollution. The real time data are got from Internet.

Package googleVis provides an interface between R and Google Chart Tools. This tools offers interactive charts which can be embedded into web pages. It is convenient that googleVis package allows user to visualise data stored in R data frames with the Google Chart Tools without uploading the data to Google.  The vignettes of this package include more useful details and information. The result as follows(screenshot)

Due to the output is html code that contains the data and references to JavaScript functions hosted by Google, please run the following code and the webpage will be generated. Note that the data only include Chinese mainland.

library(googleVis);
province<-c("CN-11","CN-12","CN-13","CN-14","CN-15","CN-21",
"CN-22","CN-23","CN-31","CN-32","CN-33","CN-34","CN-35",
"CN-36","CN-37","CN-41","CN-42","CN-43","CN-44","CN-45",
"CN-46","CN-50","CN-51","CN-52","CN-53","CN-54","CN-61",
"CN-62","CN-63","CN-64","CN-65");
AQI<-c(107,110,287,196,108,134,184,92,233,219,241,
258,57,98,251,271,279,219,65,59,34,191,188,87,35,
41,419,115,96,138,47);
Vis<-data.frame(province,AQI)
Map<-gvisGeoChart(Vis,locationvar="province",
colorvar="AQI",options=list(region="CN",displayMode="regions",
resolution="provinces",colorAxis="{colors:['lightblue','red']}"));
plot(Map);

In addition, if one needs to do some data analysis about meteorology, it is worth mentioning that package RWeather(a new package weatherData has the similar function) enables user to get meteorological data easily from  Yahoo and NOAA. For example,

> getWeatherFromYahoo("10001")
$current_condition
$current_condition$location
city region country
1 New York NY US

$current_condition$units
temperature distance pressure speed
1 F mi in mph

$current_condition$wind
chill direction speed
1 42 290 5

$current_condition$atmosphere
humidity visibility pressure rising
1 65 10 30.09 1

$current_condition$astronomy
sunrise sunset
1 7:03 am 5:13 pm

$current_condition$condition
text code temp date
1 Cloudy 26 44 Sun, 02 Feb 2014 9:50 pm EST
$forecasts
day date low high condition
1 Sun 2 Feb 2014 33 48 Rain/Snow Showers Late
2 Mon 3 Feb 2014 24 34 Snow
3 Tue 4 Feb 2014 33 37 Partly Cloudy
4 Wed 5 Feb 2014 22 37 Rain
5 Thu 6 Feb 2014 18 28 Partly Cloudy

 

To leave a comment for the author, please follow the link and comment on their blog: Chen-ang Statistics » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.