New Zealand · R

New Zealand Names

This is just showing how to process the New Zealand baby names spreadsheet provided by the New Zealand Governemnt, and also make streamgraphs, available from github with devtools::install_github(“hrbrmstr/streamgraph”)

download.file("https://smartstart.services.govt.nz/assets/files/Top-baby-names-1954-2016.xlsx", destfile="babynames.xlsx", mode="wb", method="libcurl")
library(readxl)
library(dplyr)
library(streamgraph)

female <- read_excel("~/Desktop/babynames.xlsx", 
    sheet = "Girls' Names", col_names = FALSE, 
    skip = 7)
female <- female[1:100,]
male <- read_excel("~/Desktop/babynames.xlsx", 
    sheet = "Boys' Names", col_names = FALSE, 
    skip = 7)
male <- male[1:100,]

for (i in 1:62){
  female[,(i*3)+2] <- i+1953
}
female$X190 <- 2016

for (i in 1:62){
  male[,(i*3)+2] <- i+1953
}
male$X190 <- 2016

names <- 0:62*3 + 3
numbers <- 0:62*3 + 4
years <- 0:62*3 + 5

female_names <- data.frame(name= unlist(female[,names]),
                         number= unlist(female[,numbers]),
                         year= unlist(female[,years]),
                         stringsAsFactors = FALSE)

male_names <- data.frame(name= unlist(male[,names]),
                         number= unlist(male[,numbers]),
                         year= unlist(male[,years]),
                         stringsAsFactors = FALSE)

Streamgraph of female names:

female_names %>% streamgraph(key=name, value=number, date=year) %>%
sg_legend(show=TRUE, label="Name: ")
 female
Streamgraph of male names:

male_names %>% streamgraph(key=name, value=number, date=year) %>% sg_legend(show=TRUE, label="Name: ")

male

I would note that the population is not actually shrinking, it is just names are getting more diverse

The interactive version of the stream graphs is at http://rpubs.com/thoughtfulbloke/nzbabynames

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s