Skip to content

Instantly share code, notes, and snippets.

@uribo
Created March 25, 2021 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uribo/4dd186acaf6aec9947d0f0177821bd55 to your computer and use it in GitHub Desktop.
Save uribo/4dd186acaf6aec9947d0f0177821bd55 to your computer and use it in GitHub Desktop.
電力使用率をmoon chartsで表現する🌖⚡️
library(dplyr)
library(readr)
library(ggplot2)
library(gggibbous)
library(ggtext)
d <-
read_csv("https://www.tepco.co.jp/forecast/html/images/juyo-result-j.csv",
skip = 2,
locale = locale(encoding = "cp932"))
d %>%
select(1, 2, 6) %>%
purrr::set_names(c("date", "time", "usage")) %>%
mutate(date = lubridate::as_date(date),
day = lubridate::day(date),
usage = usage,
wday = lubridate::wday(date),
week = lubridate::epiweek(date)) %>%
mutate(week = if_else(week == 53, 0, week)) %>%
filter(between(date, lubridate::as_date("2021-01-01"), lubridate::as_date("2021-01-31"))) %>%
ggplot(aes(wday, week)) +
geom_moon(aes(ratio = usage / 100, fill = usage)) +
geom_text(aes(label = usage, vjust = 4.2), size = 2.2) +
geom_text(aes(label = day, vjust = -2.7, hjust = 4, fontface = "italic"), color = "gray30", size = 1.8) +
scale_y_reverse() +
scale_fill_gradientn(colours = rev(unikn::pal_signal)) +
expand_limits(x = c(0.5), y = c(-0.5, 6.5)) +
theme_void(base_family = "YuGo-Medium",
base_size = 9) +
guides(fill = guide_colorbar(title = "使用率(%)")) +
theme(plot.margin = unit(c(0.5, 0.5, 0.5, 0.5), "lines"),
plot.title.position = "plot",
plot.title = element_textbox_simple(fill = "cornsilk"),
plot.caption = element_markdown(),
legend.direction = "horizontal",
legend.position = c(0.5, 0.1),
legend.key.width = unit(3.0, "line")) +
labs(
title = "**2021年1月の最大電力実績**<br><span style = 'font-size:8pt'>需要ピーク時における電力使用率</span>",
caption = "<span style='font-family: \"Font Awesome 5 Brands\"; color:#55acee'>&#61593;</span>@u_ribo<br>データ元: 東京電力パワーグリッド 最大電力実績カレンダー<br>https://www\\.tepco\\.co\\.jp/forecast/html/calendar-j.html")
ggsave("out.png", dpi = 320, width = 5, height = 6.2)
@uribo
Copy link
Author

uribo commented Mar 25, 2021

out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment