このレポートについて。 文献マップ「2-1 地震カタログ」で整理したデータ源(USGS FDSN / ANSS ComCat)を実際に使い、解析の出発点となる地震カタログの取得と可視化を行います。インターネット接続のある環境で Knit すると、最新のカタログを取得して下の図を再生成します(取得結果は japan_eq.rds にキャッシュし、再Knit時はそれを再利用します)。

1 パッケージ

need <- c("dplyr", "lubridate", "ggplot2", "scales", "maps")
inst <- need[!need %in% rownames(installed.packages())]
if (length(inst)) install.packages(inst, repos = "https://cloud.r-project.org")
library(dplyr); library(lubridate); library(ggplot2); library(scales); library(maps)

2 取得条件

津波を起こしうる地震を広く拾うため M≥4.5、期間は 2000 年以降、範囲は日本列島〜南西諸島〜伊豆・小笠原〜日本海溝を含むバウンディングボックスとします。

START_DATE <- as.Date("2000-01-01")
END_DATE   <- Sys.Date()
MIN_MAG    <- 4.5
MIN_LAT <- 24; MAX_LAT <- 46            # 緯度(°N)
MIN_LON <- 122; MAX_LON <- 150          # 経度(°E)
BASE    <- "https://earthquake.usgs.gov/fdsnws/event/1/query"
CACHE   <- "japan_eq.rds"

3 取得関数(FDSN・月次チャンク)

FDSN は 1 レスポンス 2 万件の上限があるため、月単位で分割取得して結合し、id で重複除去します。各月でデータが無い(HTTP 204)場合やエラーはスキップ/リトライします。

build_url <- function(start, end) {
  params <- c(
    format       = "csv",
    starttime    = format(start, "%Y-%m-%dT00:00:00"),
    endtime      = format(end,   "%Y-%m-%dT00:00:00"),
    minlatitude  = MIN_LAT, maxlatitude = MAX_LAT,
    minlongitude = MIN_LON, maxlongitude = MAX_LON,
    minmagnitude = MIN_MAG, orderby = "time-asc"
  )
  paste0(BASE, "?", paste(names(params), params, sep = "=", collapse = "&"))
}

fetch_chunk <- function(start, end, max_retry = 3, sleep = 1) {
  url <- build_url(start, end)
  for (k in seq_len(max_retry)) {
    res <- tryCatch(
      suppressWarnings(read.csv(url, stringsAsFactors = FALSE, colClasses = "character")),
      error = function(e) e)
    if (inherits(res, "error")) {
      if (grepl("204|No Content|cannot open|HTTP", res$message, ignore.case = TRUE)) return(NULL)
      Sys.sleep(sleep * k); next
    }
    return(res)
  }
  warning(sprintf("skip: %s - %s", start, end)); NULL
}

4 取得の実行(キャッシュあり)

if (file.exists(CACHE)) {
  raw <- readRDS(CACHE)
} else {
  starts <- seq(as.Date(format(START_DATE, "%Y-%m-01")), END_DATE, by = "month")
  chunks <- lapply(seq_along(starts), function(i) {
    s <- starts[i]
    e <- if (i < length(starts)) starts[i + 1] else END_DATE
    Sys.sleep(0.5)
    fetch_chunk(s, e)
  })
  raw <- dplyr::bind_rows(Filter(Negate(is.null), chunks))
  raw <- raw[!duplicated(raw$id), ]
  saveRDS(raw, CACHE)
}

5 前処理(型変換・JST・クリーニング)

eq <- raw %>%
  transmute(
    id, place, magType,
    time_utc = ymd_hms(time, tz = "UTC"),
    lat = as.numeric(latitude),
    lon = as.numeric(longitude),
    depth = as.numeric(depth),
    mag = as.numeric(mag)
  ) %>%
  mutate(time_jst = with_tz(time_utc, "Asia/Tokyo"),
         year = year(time_jst)) %>%
  filter(!is.na(mag), !is.na(depth), !is.na(lat), !is.na(lon),
         mag >= MIN_MAG,
         lat >= MIN_LAT, lat <= MAX_LAT, lon >= MIN_LON, lon <= MAX_LON)

nrow(eq)
## [1] 17098
range(eq$time_utc)
## [1] "2000-01-03 18:01:26 UTC" "2026-06-16 17:25:57 UTC"
eq %>% arrange(desc(mag)) %>%
  select(time_jst, lat, lon, depth, mag, magType, place) %>%
  head(10)

6 可視化

6.1 震央分布

world <- map_data("world")
ggplot() +
  geom_polygon(data = world, aes(long, lat, group = group),
               fill = "grey92", color = "grey80", linewidth = 0.2) +
  geom_point(data = eq, aes(lon, lat, size = mag, color = depth), alpha = 0.55) +
  scale_color_viridis_c(direction = -1, name = "Depth (km)") +
  scale_size_continuous(range = c(0.4, 5), name = "M") +
  coord_quickmap(xlim = c(MIN_LON, MAX_LON), ylim = c(MIN_LAT, MAX_LAT)) +
  labs(title = "Earthquakes near Japan (USGS FDSN)",
       subtitle = sprintf("M\u2265%.1f, %s\u2013%s", MIN_MAG, year(START_DATE), year(END_DATE)),
       x = "Longitude", y = "Latitude") +
  theme_minimal(base_size = 12)

6.2 マグニチュード頻度分布と Gutenberg–Richter 則

mag_breaks <- seq(MIN_MAG, ceiling(max(eq$mag)), by = 0.1)
gr <- data.frame(M = mag_breaks,
                 N = sapply(mag_breaks, function(m) sum(eq$mag >= m)))  # 累積(M以上の数)
ggplot(gr, aes(M, N)) +
  geom_point(color = "#17697a") +
  scale_y_log10(labels = comma) +
  labs(title = "Gutenberg–Richter relation (cumulative)",
       x = "Magnitude", y = "N (\u2265 M, log scale)") +
  theme_minimal(base_size = 12)

直線的に下がる傾きが b 値(1-6 参照)。低マグニチュード側で曲がる点が、おおよその完全性規模 Mcの目安になります。

6.3 深さの分布

ggplot(eq, aes(depth)) +
  geom_histogram(binwidth = 20, fill = "#17697a", color = "white") +
  labs(title = "Depth distribution", x = "Depth (km)", y = "Count") +
  theme_minimal(base_size = 12)

6.4 規模 × 深さ

ggplot(eq, aes(depth, mag)) +
  geom_point(aes(color = depth), alpha = 0.4) +
  scale_color_viridis_c(direction = -1, guide = "none") +
  labs(title = "Magnitude vs depth", x = "Depth (km)", y = "Magnitude") +
  theme_minimal(base_size = 12)

6.5 年ごとの地震数

eq %>% count(year) %>%
  ggplot(aes(year, n)) +
  geom_col(fill = "#17697a") +
  labs(title = "Events per year", x = "Year", y = "Count") +
  theme_minimal(base_size = 12)

7 まとめと次のステップ

  • USGS FDSN から、日本付近・2000–2026・M≥4.5 の地震カタログを再現可能な形で取得できた。
  • 震央は太平洋側のプレート境界に集中し、深さは浅部に多く、スラブ内の中・深発が裾を作る。
  • 規模頻度は G–R 則に従い、低マグニチュード側の曲がりが完全性規模 Mc の目安になる。

次回以降:規模の均質化(mb/Ms → Mw、分野3)、デクラスタリング(余震除去)、発震機構の結合(GCMT/F-net、2-2)、そして津波の有無(NOAA/JMA)を目的変数に結合して教師データを作る。

## R version 4.4.3 (2025-02-28)
## Platform: aarch64-apple-darwin20
## Running under: macOS 26.3.1
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## time zone: Asia/Tokyo
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] maps_3.4.2.1    scales_1.3.0    ggplot2_3.5.2   lubridate_1.9.4
## [5] dplyr_1.1.4    
## 
## loaded via a namespace (and not attached):
##  [1] gtable_0.3.6      jsonlite_2.0.0    compiler_4.4.3    tidyselect_1.2.1 
##  [5] jquerylib_0.1.4   yaml_2.3.10       fastmap_1.2.0     R6_2.6.1         
##  [9] labeling_0.4.3    generics_0.1.4    knitr_1.49        tibble_3.2.1     
## [13] munsell_0.5.1     bslib_0.8.0       pillar_1.10.2     rlang_1.1.6      
## [17] cachem_1.1.0      xfun_0.49         sass_0.4.9        viridisLite_0.4.2
## [21] timechange_0.3.0  cli_3.6.5         withr_3.0.2       magrittr_2.0.3   
## [25] digest_0.6.37     grid_4.4.3        rstudioapi_0.17.1 lifecycle_1.0.4  
## [29] vctrs_0.6.5       evaluate_1.0.1    glue_1.8.0        farver_2.1.2     
## [33] colorspace_2.1-1  rmarkdown_2.29    tools_4.4.3       pkgconfig_2.0.3  
## [37] htmltools_0.5.8.1