「第11回 空間データ分析3」の「日本におけるスターバックスの拡大」で作成された「starbucks.csv」を用いて、日本においてスターバックスがどのように店舗を拡大していったかを分析してください。
分析結果からわかったことを(ウォルマートの例を参考に)インラインに記述して提出してください。
また、末尾にRのコードもコピー・ペーストして提出してください。
年ごとの地図やアニメーションから次のようなことがわかる。
初店舗から数年は東京近郊で店舗を拡大した。
1990年後半から大阪や神戸に出店し、2000年までに名古屋、福岡、仙台などの大都市に拡大した。
2005年までに日本海側の都市や北海道および沖縄に店舗を拡大した。
2006年以降も全国に店舗を拡大し続けている。
===== 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
データ starbucs.csv を読み込む。
fileEncoding = "utf8" のようにエンコーディングを指定する。日付の変数 opendate を R の Date オブジェクトに変更する。
starbucks$opendate <- as.Date(starbucks$opendate)
starbucks <- subset(starbucks, is.na(opendate) == FALSE) # 開店日がないデータを削除mapdata パッケージを読み込む。## Loading required package: maps
starbucks.map を作成する。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.map を用いて、日本1号店がオープンした1996年から2000年までの各年と、それ以降の5年ごとに地図を作成する。
## 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")上記の地図から次のようなことがわかる。
初店舗から数年は東京近郊で店舗を拡大した。
1990年後半から大阪や神戸に出店し、2000年までに名古屋、福岡、仙台などの大都市に拡大した。
2005年までに日本海側の都市や北海道および沖縄に店舗を拡大した。
2006年以降も全国に店舗を拡大し続けている。
また、以下のようにアニメーションを作成することもできる。
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