Skip to content

Instantly share code, notes, and snippets.

@uribo
Last active October 7, 2021 21:43
Show Gist options
  • Save uribo/6b4cbe48ae9df0053f5558f7e1b98fd6 to your computer and use it in GitHub Desktop.
Save uribo/6b4cbe48ae9df0053f5558f7e1b98fd6 to your computer and use it in GitHub Desktop.
複数地点の潮位データをプロット
library(dplyr)
library(jmastats)
library(ggplot2)
library(ggforce)
# 対象地点のデータを取得 -------------------------------------------------------------
# 東京
df_tk <-
read_tide_level(.year = 2020, .month = 8, .stn = "TK")
# 能登
df_sz <-
read_tide_level(.year = 2020, .month = 8, .stn = "SZ")
# 毎時潮位と満潮・干潮の潮位に分ける -------------------------------------------------------
# hourlyが毎時潮位、tideが満潮・干潮の潮位
df_tk_long <-
df_tk %>%
pivot_tide_level()
df_sz_long <-
df_sz %>%
pivot_tide_level()
# プロット --------------------------------------------------------------------
# bind_rows()で2地点の毎時潮位データを結合
# aes(group = stn) の指定で地点別に描画するようにする
p <-
df_tk_long %>%
purrr::pluck("hourly") %>%
bind_rows(
df_sz_long %>%
purrr::pluck("hourly")
) %>%
ggplot(aes(datetime, tide_value, group = stn, color = stn)) +
geom_line() +
scale_x_datetime(date_labels = "%m/%d") +
theme_light()
# 表示
p
# パネル状に表示する
p +
facet_wrap(~ stn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment