March 26, 2014

How did Sophia spread in the U.S.?

Preparation

In the previous post, I founded popular baby names in U.S. As for female, the most popular baby name is Sophia. As you can see, Sophia has become popular recently, actually, has incresed sharply from 1990s to 2000s.

In today's post, I will graphically check the area characteristics of Sophia with rCharts.

Preparation

As with the approach of the previous post, I prepare the data with plyr package. Furthermore, I add the prop column to the data with dplyr package. It denotes proportion in each states. Okay, we are all ready. Let's visualize it.

library(plyr)
setwd("./downloads/namesbystate")
fs <- list.files()
fs <- fs[fs!="StateReadMe.pdf"]
dat_babyname <- ldply(as.list(fs), function(x)read.csv(x, as.is=TRUE, header=FALSE))
colnames(dat_babyname) <- c("state", "sex", "year", "name", "freq")

library(dplyr)
sophia <- dat_babyname %.% 
  group_by(state,sex,year) %.% 
  mutate(prop=round(freq*100/sum(freq),2)) %.%
  filter(name=="Sophia")

Visualize 2012

First, I visualize the area trend of Sophia in 2012. Here's the result. The higher the props are , the darker the colors get . You can see Sophia is more popular in the west side of the U.S than in the east.

library(rMaps)
sophia2012 <- subset(sophia, year==2012)
isophia2012 <- ichoropleth(prop~state,  data=sophia2012, pal="Reds", 
                           geographyConfig=list(popupTemplate="#!function(geo, data) {
                                                return '<div class=\"hoverinfo\"><strong>'+
                                                geo.properties.name+
                                                '<br>Prop: ' + data.prop +
                                                '</strong></div>';}!#"))
isophia2012$show("iframesrc", cdn = TRUE)

Visualize 1910-2011

Next I visualize the transition of Sophia. On the contrary to the present, it doesn't seem that Sophia is popular in the west side at the beginning of the 20th century. However, it spread to the south after the middle of 1960s.

isophia <- ichoropleth(prop~state, data=sophia, pal="Reds", animate="year", play=TRUE,
                       geographyConfig=list(popupTemplate="#!function(geo, data) {
                                            return '<div class=\"hoverinfo\"><strong>'+
                                            geo.properties.name+
                                            '<br>Rank: ' + data.prop +
                                            '</strong></div>';}!#"))
isophia$show("iframesrc", cdn = TRUE)

No comments:

Post a Comment