Data Visualization of PM 2.5 Levels in Five Chinese Cities

Posted on Jul 30, 2018

The skills the authors demonstrated here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.


     Data shows that due to the rapid industrialization of the past 30 years and still lax environmental laws, air and water pollution has become a major issue in China in recent years. Among the air pollutants, micro-particles (P.M) pose a serious threat to public health. PM 2.5 refers to particles with diameter equal to or less than 2.5 micro-meters. Due to their small size, they can penetrate deep inside people's lungs and even into their bloodstream, making them especially hazardous to health.

I was born in Guangzhou, China, and though have emigrated to the U.S. since I was 10 years old, I still go back to visit family in China regularly. This issue is therefore something I want to investigate not just for academic, but personal reasons.    


     The data set used is available from Kaggle It provides PM 2.5 measurements in Beijing, Shenyang, Shanghai, Chengdu, and Guangzhou from 2010 to 2015. In addition to PM 2.5 levels, it also gives information on variables like temperature, humidity, air pressure, precipitation, etc. The wide scope of the data affords us ample ways to analyze PM 2.5 problem in China. The main questions that I want to answer through this project are:

  • How do PM 2.5 levels differ in different regions in China?
  • Do other variables like temperature, humidity, and air pressure correlate with PM 2.5 levels?
  • Do PM 2.5 levels vary at different times of the year?
  • Have PM 2.5 levels improve over the five year period?     


     As downloaded, the data set is pretty clean. It is actually separated into five different .csv files for the five cities, so the first pre-processing step is to merge the different files into one data table. Also, for each city, the PM 2.5 levels were measured in three to four different locations. To facilitate analysis, and since we are making comparisons between the cities and not interested in the variation of PM 2.5 levels within each city, I averaged the PM 2.5 levels across all locations in each city and used that as the PM 2.5 level for that city.

After performing the above step and combining the .csv files, I removed all rows which do not have a reading for PM 2.5 level. NA values in other variables were still accepted. Note that data is not available for all cities in the entire time period from 2010 to 2015. Only Beijing has data in 2010-2011, while others start from 2011 to 2013. Final pre-processing step involved combining and converting the year-month-day columns into date format, which allows time-series plots to be possible.

Data Visualization:

     Since the PM 2.5 data includes geographical information, the most natural way to visualize and compare PM 2.5 levels is through a map. The first visualization tool I used is a GoogleVis GeoChart which shows the mean PM 2.5 levels in the five Chinese cities over a user-defined time period. Each circle is drawn and colored according to the measured PM 2.5 level during that time period.

From the map, we can clearly see that over any time period, the mean PM 2.5 levels in northern cities like Beijing and Shenyang is much higher than southern cities like Shanghai and Guangzhou. Chengdu in the interior lies somewhere in between. Occasionally it can be better than Shenyang, but it is still worse than Guangzhou and Shanghai in general. The mean values for PM 2.5 range from 51 µg ⁄ m3 in Guangzhou to 95 µg ⁄ min Beijing.

According to the EPA, a 24 hour exposure to PM 2.5 levels higher than 35.4 µg ⁄ mis consider unhealthy. Thus, all cities in the data set have mean values higher than healthy and some cities can have peak values in the very unhealthy to hazardous range.  


Mean PM 2.5 Levels from 2010 - 2015

     To compare PM 2.5 level to the other variables in the data set, I made a scatter plot. While I could have chosen more, the three variables that I choose to study vs. PM 2.5 level were temperature, dew point, and air pressure. For each city and year, the daily value of PM 2.5 and the selected variable were plotted.

Viewing data this way, it is difficult to find the pattern due to the sheer number of points. Therefore, I included an option to aggregate the data into monthly averages. I also grouped the points by season, so it is easier to see pattern if one exists. Looking at the monthly data points, we can discern a pattern in the temperature vs. PM 2.5 plot. A qualitative examination shows that the PM 2.5 levels are negatively correlated with temperature. For the plots of PM 2.5 vs. dew point and air pressure, no obvious correlation is observed. 

     To examine the time evolution of the PM 2.5 levels, one of my ideas is to make a histogram plot. Basically, I am looking at the daily PM 2.5 level of a city in the course of a year and counting the frequency of days that a range of PM 2.5 level occurs. What I want to observe is that as I advance the years, the histogram would shift to the right, meaning there would be more days with lower PM 2.5 level. In practice, this proved to be difficult, as the range of PM 2.5 levels fluctuate from year to year, changing to bin size and making comparison between years difficult. I tried to fix the bin width for each plot, but still could not completely solve the problem.


Histogram for Beijing in 2010

     The time evolution of PM 2.5 levels were visualized through a time series plot. Here, I plot the whole series of PM 2.5 data as function of time (date), allowing option for user to select city(cities) to displayed. One very noticeable feature of the graph is that the PM 2.5 level peaks every year around winter time. This is observed for all cities. One explanation for this, especially for the northern cities like Beijing and Shenyang, is that China still uses coal as main source of energy for home heating, thus creating more pollutants in the winter time.

For southern cities like Guangzhou, though, the explanation is harder. My conjecture is maybe more intensive industrial activities in the winter? To definitely see if there is improvement over the years, I used a bar graph to plot the yearly average PM 2.5 levels for all five cities. Though not all cities are as obvious, but there is definite decrease in PM 2.5 levels for all cities in the time period studied. This is good news, as the data shows that though the PM 2.5 levels are very unhealthy in general for cities in China, the situation is improving. If we can get the more recent data from 2016 to now, we can see if the trend is just an aberration or real improvement is being made.


     In conclusion, in the project I have studied the PM 2.5 levels for five Chinese cities from 2010 to 2015. While the plots and graphs I have made can definitely helped me answer the questions that I started with, the analyses I must say are all qualitative in nature. With the time restriction I had for this project, I simply did not have time to conduct more detailed statistical analysis of the problem. That hopefully I can come back to in the future.         

Coding Challenges:

     During the work on this project, there were a few challenges I had to overcome to complete it. One is simply familiarize myself with how the inputs and outputs work in a Shiny app. I decided to use GoogleVis for all my visualizations, and for each plot, I had to manipulate the data into a form that is recognizable by GoogleVis to make the plot that I wanted. The most difficult is making the scatter plot. Since I wanted to group the data points by season, I had to separate the values of PM 2.5 into four separate columns by season, then assign the four columns as separate variables.

However, for cities with incomplete data in a year, such as Guangzhou in 2011, the missing data for a season would generate an entire column of NA values, which would caused an error for the plot.

Eventually, I was able to find a solution. Instead of generating the four columns for seasons by hand using ifelse statements, which would generate a column with all missing values if there is no data for that season, I used the spread function in the tidyr package to unpack the data automatically, which would only generate columns for seasons that have data. This avoids passing columns of all NA values to GoogleVis plot function which caused the error. I think able to find the cause and able to overcome that problem in my app is one of the more valuable things that I learn from making this app.      

Future Work:

     As I mentioned before, this project so far has been a very qualitative analysis of the PM 2.5 problem in China. One area that I can definitely work on is to use more quantitative methods. For example, correlation relation between the several variables I studied with PM 2.5 can be examined with a Chi Square test. The yearly average PM 2.5 levels for each city can also be analyze with an ANOVA test to see if their mean is truly decreasing or just is the result of statistical variation. I can also look into how to incorporate data from other areas, such as industry, traffic, and weather/climate to gain deeper insight into the PM 2.5 problem in China and offer possible viable solutions to this problem.  

About Author

Arthur Yu

I have a PhD in Physics from UC Irvine, following my B.A. degree in Physics and Mathematics from NYU. My main interests in data science are understanding and improving machine learning models and algorithms. I hope to learn...
View all posts by Arthur Yu >

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI