Last active
July 11, 2025 00:17
-
-
Save abikoushi/b90bfa34cb76d1b36580526916b4eeea to your computer and use it in GitHub Desktop.
熊谷の最高気温をプロット
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(readr) | |
library(dplyr) | |
library(ggplot2) | |
## data is available from | |
## https://www.data.jma.go.jp/risk/obsdl/index.php | |
dat = read_csv("./Downloads/data.csv", skip = 6, | |
col_names = c("date","Temp","hinshitsu","kinitsu")) | |
dat = tidyr::separate(dat, | |
date,into = c("year","month","date"), | |
sep="/") | |
#2000 is dummy year for as.Date | |
dat_all = mutate(dat, month_date = as.Date(paste("2000", month, date, sep = "/"))) %>% | |
mutate(year = as.integer(year)) | |
m = mean(dat_all$Temp) | |
p1 = ggplot(dat_all, aes(x=month_date, y=Temp, colour=year, group=year)) + | |
geom_line(linewidth= 0.1)+ | |
scale_color_viridis_c()+ | |
scale_x_date(date_labels = "%m/%d", date_breaks = "7 day")+ | |
theme_classic(16, base_family = "Osaka")+ | |
labs(x="月/日", y="最高気温(℃)", colour="年", | |
title = "熊谷の最高気温(7月〜9月)\nhttps://www.data.jma.go.jp/risk/obsdl/index.php")+ | |
theme(axis.text.x = element_text(angle = 90)) | |
ggsave(plot = p1, filename = "kumagaya1.png", | |
width = 8, height = 8) | |
p2 =ggplot(dat_all, aes(x=month_date, y=Temp, colour=year, group=year)) + | |
geom_point(alpha = 0.5)+ | |
scale_color_viridis_c()+ | |
scale_x_date(date_labels = "%m/%d", date_breaks = "7 day")+ | |
theme_classic(16, base_family = "Osaka")+ | |
labs(x="月/日", y="最高気温(℃)", colour="年", | |
title = "熊谷の最高気温(7月〜9月)\nhttps://www.data.jma.go.jp/risk/obsdl/index.php")+ | |
theme(axis.text.x = element_text(angle = 90)) | |
ggsave(plot = p2, filename = "kumagaya2.png", | |
width = 8, height = 8) | |
p3 = ggplot(dat_all, aes(x=month_date, fill=Temp, y=year, group=year)) + | |
geom_tile()+ | |
scale_fill_gradient2(midpoint = m, low = "cornflowerblue", high = "orangered")+ | |
scale_y_reverse()+ | |
scale_x_date(date_labels = "%m/%d", date_breaks = "7 day")+ | |
theme_classic(16, base_family = "Osaka")+ | |
labs(x="月/日", fill="最高気温(℃)", y="年", | |
title = "熊谷の最高気温(7月〜9月)\nhttps://www.data.jma.go.jp/risk/obsdl/index.php")+ | |
theme(axis.text.x = element_text(angle = 90)) | |
print(p3) | |
ggsave(plot = p3, filename = "kumagaya3.png", | |
width = 8, height = 8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment