Skip to content

Instantly share code, notes, and snippets.

@uribo
Last active February 2, 2021 00:26
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/3cdcdfa6c56401eb2ab124982aa698a7 to your computer and use it in GitHub Desktop.
Save uribo/3cdcdfa6c56401eb2ab124982aa698a7 to your computer and use it in GitHub Desktop.
zipangu v0.2.2
####################################
# zipangu v0.2.2
####################################
library(zipangu)
library(ggplot2)
library(patchwork)
theme_set(theme_bw(base_family = suryulib::jpfont(), base_size = 6))
# ベクトル化 -------------------------------------------------------------------
convert_jdate(c("令和3年2月1日", "令和元年5月1日", "平31年4月1日"))
#> [1] "2021-02-01" "2019-05-01" "2019-04-01"
# 複数桁の漢数字のアラビア数字変換 --------------------------------------------------------
# 京までの位に対応して漢数字をアラビア数字に変換
kansuji2arabic_num("二千二十")
#> [1] "2020"
kansuji2arabic_num("一億二千三百四十五万六千七百八十九")
#> [1] "123456789"
# 漢数字部分だけをアラビア数字に変換
kansuji2arabic_str("金一億二千三百四十五万六千七百八十九円")
#> [1] "金123456789円"
# 漢数字のラベル機能 --------------------------------------------------------
ja_pop <- structure(list(年 = c("1955", "1960", "1965", "1970", "1975", "1980"),
総人口 = c(89275529, 93418501, 98274961, 103720060, 111939643, 117060396)),
row.names = c(NA, -6L),
class = c("tbl_df", "tbl", "data.frame"))
p <-
ja_pop %>%
ggplot() +
geom_bar(aes(x = 年, y = 総人口), stat = "identity")
p1 <-
p +
labs(title = "ggplot2のデフォルト",
subtitle = "桁数の多い数字をそのまま出力")
p2 <-
p +
scale_y_continuous(labels = label_kansuji()) +
labs(title = "zipangu::label_kansuji()",
subtitle = "漢数字のラベルを利用")
p3 <-
p +
scale_y_continuous(labels = label_kansuji_suffix()) +
labs(title = "zipangu::label_kansuji_suffix()",
subtitle = "複数の単位があるときに便利")
p1 + p2 + p3 +
plot_layout(nrow = 1)
ggsave(filename = "out.png", width = 8, height = 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment