Visualization of AQI

February 2, 2014
By

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

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

Package googleVis providesan interface between R and GoogleChart Tools. This tools o?ers interactive charts which can beembedded into web pages. It is convenient that googleVispackage allows user to visualise datastored in R data frames with the Google Chart Tools without uploading thedata to Google. Thevignettes of this package include more useful details and information. The result as follows(screenshot)

AQI

Due to the output is html code thatcontains 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 packageweatherData has the similar function) enables user to getmeteorological 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 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


Sponsors

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)