課題説明

「第11回 空間データ分析3」の「日本におけるスターバックスの拡大」で作成された「starbucks.csv」を用いて、日本においてスターバックスがどのように店舗を拡大していったかを分析してください。

分析結果からわかったことを(ウォルマートの例を参考に)インラインに記述して提出してください。

また、末尾にRのコードもコピー・ペーストして提出してください。

解答

年ごとの地図やアニメーションから次のようなことがわかる。

===== Rの出力結果 =====

> starbucks <- read.csv("starbucks.csv", fileEncoding = "utf8")
> 
> starbucks$opendate <- as.Date(starbucks$opendate)
> starbucks <- subset(starbucks, is.na(opendate) == FALSE) # 開店日がないデータを削除
> 
> library(mapdata)
> 
> starbucks.map <- function(data, date) {
+   starbucks <- subset(data, subset = (opendate <= date))
+   map("japan", interior = FALSE)
+   map("japan", boundary = FALSE, lty = 2, add = TRUE)
+   points(starbucks$long, starbucks$lat, col = starbucks$color, pch = 19, cex = 0.5)
+   map.axes()
+ }
> 
> ## starbucksロゴの色
> starbucks$color <- rgb(red = 0.0118, green = 0.4, blue = 0.2078, alpha = 1/3)
> 
> starbucks.map(starbucks, as.Date("1996-12-31"))
> title("1996")
> 
> starbucks.map(starbucks, as.Date("1997-12-31"))
> title("1997")
> 
> starbucks.map(starbucks, as.Date("1998-12-31"))
> title("1998")
> 
> starbucks.map(starbucks, as.Date("1999-12-31"))
> title("1999")
> 
> starbucks.map(starbucks, as.Date("2000-12-31"))
> title("2000")
> 
> starbucks.map(starbucks, as.Date("2005-12-31"))
> title("2005")
> 
> starbucks.map(starbucks, as.Date("2010-12-31"))
> title("2010")
> 
> starbucks.map(starbucks, as.Date("2015-12-31"))
> title("2015")
> 
> starbucks.map(starbucks, as.Date("2020-12-31"))
> title("2020")
> 
> 
> n <- 25 # アニメーション化する地図の数
> 
> dates <- seq(from = min(starbucks$opendate), 
+              to = max(starbucks$opendate), length.out = n)
> 
> # install.packages("animation") # インストールしていない場合
> library("animation")
> saveHTML({
+   for (i in 1:length(dates)) {
+     starbucks.map(starbucks, dates[i])
+     title(dates[i])
+   }
+ }, title = "Starbucks Japan Expansion", htmlfile = "starbucks.html",
+ outdir = getwd(), autobrowse = FALSE)
animation option 'nmax' changed: 50 --> 25
animation option 'nmax' changed: 25 --> 50
HTML file created at: starbucks.html

解説

starbucks <- read.csv("starbucks.csv", fileEncoding = "utf8")
starbucks$opendate <- as.Date(starbucks$opendate)
starbucks <- subset(starbucks, is.na(opendate) == FALSE) # 開店日がないデータを削除
library(mapdata)
## Loading required package: maps
starbucks.map <- function(data, date) {
  starbucks <- subset(data, subset = (opendate <= date))
  map("japan", interior = FALSE)
  map("japan", boundary = FALSE, lty = 2, add = TRUE)
  points(starbucks$long, starbucks$lat, col = starbucks$color, pch = 19, cex = 0.5)
  map.axes()
}
## starbucksロゴの色
starbucks$color <- rgb(red = 0.0118, green = 0.4, blue = 0.2078, alpha = 1/3)

starbucks.map(starbucks, as.Date("1996-12-31"))
title("1996")

starbucks.map(starbucks, as.Date("1997-12-31"))
title("1997")

starbucks.map(starbucks, as.Date("1998-12-31"))
title("1998")

starbucks.map(starbucks, as.Date("1999-12-31"))
title("1999")

starbucks.map(starbucks, as.Date("2000-12-31"))
title("2000")

starbucks.map(starbucks, as.Date("2005-12-31"))
title("2005")

starbucks.map(starbucks, as.Date("2010-12-31"))
title("2010")

starbucks.map(starbucks, as.Date("2015-12-31"))
title("2015")

starbucks.map(starbucks, as.Date("2020-12-31"))
title("2020")

n <- 25 # アニメーション化する地図の数

dates <- seq(from = min(starbucks$opendate), 
             to = max(starbucks$opendate), length.out = n)

# install.packages("animation") # インストールしていない場合
library("animation")
saveHTML({
  for (i in 1:length(dates)) {
    starbucks.map(starbucks, dates[i])
    title(dates[i])
  }
}, title = "Starbucks Japan Expansion", htmlfile = "starbucks.html",
outdir = getwd(), autobrowse = FALSE)
## HTML file created at: starbucks.html