11/18/2018

Introduction

In this small project, I will analyze US States Popluation data from 2010 to 2017. The data is download from goverment census website. In this project, I will only analyze all Asian Californians to see how Asian population is booming in California with Plotly animation method.

Frist, let's input data.

df <- read.csv("https://www2.census.gov/programs-surveys/popest/datasets/2010-2017/state/asrh/sc-est2017-alldata6.csv")

Data Selection

Select all asian in California despite the origin

library(dplyr)
caAsianPop <- df %>% filter(SEX == 0 & NAME == "California" 
                            & RACE == 4 & ORIGIN == 0)

Now, caAsianPop has all male and female Asian Californians population from all age group and despite their region from 2010 to 2017.

Create a Data Frame for Asian Californias from 2010 to 2017

Let's sum all the population columns to get total population in each year. Then, let's creat a dataframe CA to store it with right format.

caAsian <- apply(caAsianPop[,-(1:11)], 2, sum)
CA <- data.frame(
  year = 2010:2017, 
  pop = caAsian
)

CA
##                 year     pop
## POPESTIMATE2010 2010 5064237
## POPESTIMATE2011 2011 5178171
## POPESTIMATE2012 2012 5296441
## POPESTIMATE2013 2013 5424022
## POPESTIMATE2014 2014 5564407
## POPESTIMATE2015 2015 5713214
## POPESTIMATE2016 2016 5855369
## POPESTIMATE2017 2017 5993089

Plotly

Now, let's import plotly library

library(plotly)

The library is loaded, let's output the result in Animation format.

p <- CA %>%
  plot_ly(x = ~year,y = ~pop, frame = ~year,type = 'scatter',
          mode = 'markers',showlegend = F) %>% 
    animation_opts(2000, easing = "quad", redraw = FALSE)

Graph

Thank you