This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
# 変数の消去
rm(list = ls())
# パッケージ `pacman`を使って必要なパッケージをインストール
if(!require("pacman")) install.packages("pacman")
## Loading required package: pacman
pacman::p_load("tidyverse",
"gt",
"skimr",
"showtext",
"anomalize")
# 表示を科学表示から変更
options(scipen = 999)
# 日本語フォントの追加
# フォントの追加と設定(適宜日本語フォントを指定してください)
font_add_google("Noto Sans JP", "noto")
showtext::showtext_auto()
library(readxl)
#データフレームをdat_xとする
dat_x <- read_excel("~/Desktop/data/2024数理.xlsx")
View(dat_x)
summary(dat_x)
## 年月 合計月別漁獲量(トン)
## Length:77 Min. : 0.00
## Class :character 1st Qu.: 14.87
## Mode :character Median : 570.13
## Mean :1052.42
## 3rd Qu.:1708.21
## Max. :4402.84
この時点で、一月の最大が四千トン以上超えている魚は主要魚種に限られるため、三陸で漁獲量が少ない魚種は除く
str(dat_x)
## tibble [77 × 2] (S3: tbl_df/tbl/data.frame)
## $ 年月 : chr [1:77] "2015年8月" "2015年9月" "2015年10月" "2015年11月" ...
## $ 合計月別漁獲量(トン): num [1:77] 1107 1096 2004 4403 2463 ...
# $年月がchr型だったため、chr型からDate型に変換
# 文字列の「年」と「月」を削除し、年と月をハイフンで結び、最後に日を"01"として追加
dat_x$年月 <- as.Date(paste0(sub("年", "-", sub("月", "", dat_x$年月)), "-01"), format = "%Y-%m-%d")
# 年月をDateに、合計特別漁獲量(トン)をTotal_monthly_catches(ton)にする
colnames(dat_x) <- c("Date", "Total_monthly_catches")
#折れ線グラフで傾向を見てみる
ggplot(dat_x, aes(x = Date, y = Total_monthly_catches))+
geom_bar(stat='identity')
2020年、2021年で漁獲量が減少していることと、かなり極端な月別漁獲量変化があることが分かった。 また、11月周辺にまとまった漁獲があることから、秋に漁獲が増えるサケかサンマだと予想する。
#各年ごとの変化を細かくみるために、各年ごとのデータフレームを作成する。
dat_x_2015 <- subset(dat_x, format(Date, "%Y") == "2015")
dat_x_2016 <- subset(dat_x, format(Date, "%Y") == "2016")
dat_x_2017 <- subset(dat_x, format(Date, "%Y") == "2017")
dat_x_2018 <- subset(dat_x, format(Date, "%Y") == "2018")
dat_x_2019 <- subset(dat_x, format(Date, "%Y") == "2019")
dat_x_2020 <- subset(dat_x, format(Date, "%Y") == "2020")
dat_x_2021 <- subset(dat_x, format(Date, "%Y") == "2021")
ggplot(dat_x_2015, aes(x = Date, y = Total_monthly_catches))+
geom_bar(stat='identity')
ggplot(dat_x_2016, aes(x = Date, y = Total_monthly_catches))+
geom_bar(stat='identity')
ggplot(dat_x_2017, aes(x = Date, y = Total_monthly_catches))+
geom_bar(stat='identity')
ggplot(dat_x_2018, aes(x = Date, y = Total_monthly_catches))+
geom_bar(stat='identity')
ggplot(dat_x_2019, aes(x = Date, y = Total_monthly_catches))+
geom_bar(stat='identity')
ggplot(dat_x_2020, aes(x = Date, y = Total_monthly_catches))+
geom_bar(stat='identity')
ggplot(dat_x_2021, aes(x = Date, y = Total_monthly_catches))+
geom_bar(stat='identity')
各年ごとの図から、サンマは違うと考える。理由は秋刀魚のサンマ漁の解禁日は8月〜9月であるが、それ以前にも漁獲されていることがグラフから判断できるからである。
年ごとの漁獲量の変化をまとめるために、各年ごとの水揚げ量をまとめる
# 年を抽出して、年ごとの漁獲量を合計
yearly_catch <- dat_x %>%
mutate(Year = substr(Date, 1, 4)) %>% # 年を抽出
group_by(Year) %>% # 年でグループ化
summarise(TotalCatch = sum(Total_monthly_catches)) # 漁獲量を合計
ggplot(yearly_catch, aes(Year, TotalCatch)) + geom_bar(stat = "identity")
年ごとの漁獲量変動のグラフから、2017、2018年の漁獲量が多く、2021年の漁獲量が急激に減少していることがわかる。また、2021年はサケの漁獲量が大幅に下がった年でもある。 まとめに、この魚は漁業規模から三陸の重要な魚種の一つであるとわかり、季節性からは秋や冬に最盛期を迎え、2月から4月は漁獲がないとわかる。そして2021年に不漁が起こっているという漁業規模・季節性・年変化の三つの観点から、この魚種はサケであると考える。