NYC Data Science Academy| Blog
Bootcamps
Lifetime Job Support Available Financing Available
Bootcamps
Data Science with Machine Learning Flagship ๐Ÿ† Data Analytics Bootcamp Artificial Intelligence Bootcamp New Release ๐ŸŽ‰
Free Lesson
Intro to Data Science New Release ๐ŸŽ‰
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook Graduate Outcomes Must See ๐Ÿ”ฅ
Alumni
Success Stories Testimonials Alumni Directory Alumni Exclusive Study Program
Courses
View Bundled Courses
Financing Available
Bootcamp Prep Popular ๐Ÿ”ฅ Data Science Mastery Data Science Launchpad with Python View AI Courses Generative AI for Everyone New ๐ŸŽ‰ Generative AI for Finance New ๐ŸŽ‰ Generative AI for Marketing New ๐ŸŽ‰
Bundle Up
Learn More and Save More
Combination of data science courses.
View Data Science Courses
Beginner
Introductory Python
Intermediate
Data Science Python: Data Analysis and Visualization Popular ๐Ÿ”ฅ Data Science R: Data Analysis and Visualization
Advanced
Data Science Python: Machine Learning Popular ๐Ÿ”ฅ Data Science R: Machine Learning Designing and Implementing Production MLOps New ๐ŸŽ‰ Natural Language Processing for Production (NLP) New ๐ŸŽ‰
Find Inspiration
Get Course Recommendation Must Try ๐Ÿ’Ž An Ultimate Guide to Become a Data Scientist
For Companies
For Companies
Corporate Offerings Hiring Partners Candidate Portfolio Hire Our Graduates
Students Work
Students Work
All Posts Capstone Data Visualization Machine Learning Python Projects R Projects
Tutorials
About
About
About Us Accreditation Contact Us Join Us FAQ Webinars Subscription An Ultimate Guide to
Become a Data Scientist
    Login
NYC Data Science Acedemy
Bootcamps
Courses
Students Work
About
Bootcamps
Bootcamps
Data Science with Machine Learning Flagship
Data Analytics Bootcamp
Artificial Intelligence Bootcamp New Release ๐ŸŽ‰
Free Lessons
Intro to Data Science New Release ๐ŸŽ‰
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook
Graduate Outcomes Must See ๐Ÿ”ฅ
Alumni
Success Stories
Testimonials
Alumni Directory
Alumni Exclusive Study Program
Courses
Bundles
financing available
View All Bundles
Bootcamp Prep
Data Science Mastery
Data Science Launchpad with Python NEW!
View AI Courses
Generative AI for Everyone
Generative AI for Finance
Generative AI for Marketing
View Data Science Courses
View All Professional Development Courses
Beginner
Introductory Python
Intermediate
Python: Data Analysis and Visualization
R: Data Analysis and Visualization
Advanced
Python: Machine Learning
R: Machine Learning
Designing and Implementing Production MLOps
Natural Language Processing for Production (NLP)
For Companies
Corporate Offerings
Hiring Partners
Candidate Portfolio
Hire Our Graduates
Students Work
All Posts
Capstone
Data Visualization
Machine Learning
Python Projects
R Projects
About
Accreditation
About Us
Contact Us
Join Us
FAQ
Webinars
Subscription
An Ultimate Guide to Become a Data Scientist
Tutorials
Data Analytics
  • Learn Pandas
  • Learn NumPy
  • Learn SciPy
  • Learn Matplotlib
Machine Learning
  • Boosting
  • Random Forest
  • Linear Regression
  • Decision Tree
  • PCA
Interview by Companies
  • JPMC
  • Google
  • Facebook
Artificial Intelligence
  • Learn Generative AI
  • Learn ChatGPT-3.5
  • Learn ChatGPT-4
  • Learn Google Bard
Coding
  • Learn Python
  • Learn SQL
  • Learn MySQL
  • Learn NoSQL
  • Learn PySpark
  • Learn PyTorch
Interview Questions
  • Python Hard
  • R Easy
  • R Hard
  • SQL Easy
  • SQL Hard
  • Python Easy
Data Science Blog > R Shiny > Data Visualization of PM 2.5 Levels in Five Chinese Cities

Data Visualization of PM 2.5 Levels in Five Chinese Cities

Arthur Yu
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.

Overview:

     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.    

Data:

     The data set used is available from Kaggle: https://www.kaggle.com/uciml/pm25-data-for-five-chinese-cities. 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?     

 Pre-Processing:

     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 โ„ m3 in Beijing.

According to the EPA, a 24 hour exposure to PM 2.5 levels higher than 35.4 ยตg โ„ m3 is 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.  

data

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.

data

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.

data

     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 y 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

Cancel reply

You must be logged in to post a comment.

No comments found.

View Posts by Categories

All Posts 2399 posts
AI 7 posts
AI Agent 2 posts
AI-based hotel recommendation 1 posts
AIForGood 1 posts
Alumni 60 posts
Animated Maps 1 posts
APIs 41 posts
Artificial Intelligence 2 posts
Artificial Intelligence 2 posts
AWS 13 posts
Banking 1 posts
Big Data 50 posts
Branch Analysis 1 posts
Capstone 206 posts
Career Education 7 posts
CLIP 1 posts
Community 72 posts
Congestion Zone 1 posts
Content Recommendation 1 posts
Cosine SImilarity 1 posts
Data Analysis 5 posts
Data Engineering 1 posts
Data Engineering 3 posts
Data Science 7 posts
Data Science News and Sharing 73 posts
Data Visualization 324 posts
Events 5 posts
Featured 37 posts
Function calling 1 posts
FutureTech 1 posts
Generative AI 5 posts
Hadoop 13 posts
Image Classification 1 posts
Innovation 2 posts
Kmeans Cluster 1 posts
LLM 6 posts
Machine Learning 364 posts
Marketing 1 posts
Meetup 144 posts
MLOPs 1 posts
Model Deployment 1 posts
Nagamas69 1 posts
NLP 1 posts
OpenAI 5 posts
OpenNYC Data 1 posts
pySpark 1 posts
Python 16 posts
Python 458 posts
Python data analysis 4 posts
Python Shiny 2 posts
R 404 posts
R Data Analysis 1 posts
R Shiny 560 posts
R Visualization 445 posts
RAG 1 posts
RoBERTa 1 posts
semantic rearch 2 posts
Spark 17 posts
SQL 1 posts
Streamlit 2 posts
Student Works 1687 posts
Tableau 12 posts
TensorFlow 3 posts
Traffic 1 posts
User Preference Modeling 1 posts
Vector database 2 posts
Web Scraping 483 posts
wukong138 1 posts

Our Recent Popular Posts

AI 4 AI: ChatGPT Unifies My Blog Posts
by Vinod Chugani
Dec 18, 2022
Meet Your Machine Learning Mentors: Kyle Gallatin
by Vivian Zhang
Nov 4, 2020
NICU Admissions and CCHD: Predicting Based on Data Analysis
by Paul Lee, Aron Berke, Bee Kim, Bettina Meier and Ira Villar
Jan 7, 2020

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 ChatGPT 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 football 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 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

NYC Data Science Academy

NYC Data Science Academy teaches data science, trains companies and their employees to better profit from data, excels at big data project consulting, and connects trained Data Scientists to our industry.

NYC Data Science Academy is licensed by New York State Education Department.

Get detailed curriculum information about our
amazing bootcamp!

Please enter a valid email address
Sign up completed. Thank you!

Offerings

  • HOME
  • DATA SCIENCE BOOTCAMP
  • ONLINE DATA SCIENCE BOOTCAMP
  • Professional Development Courses
  • CORPORATE OFFERINGS
  • HIRING PARTNERS
  • About

  • About Us
  • Alumni
  • Blog
  • FAQ
  • Contact Us
  • Refund Policy
  • Join Us
  • SOCIAL MEDIA

    ยฉ 2025 NYC Data Science Academy
    All rights reserved. | Site Map
    Privacy Policy | Terms of Service
    Bootcamp Application