【R】string2path
2021年8月5日
1. はじめに
string2pathは、名前から想像できるように文字の外形pathを作ってくれるパッケージです。
2. インストール
CRANからインストールできます。
install.packages("string2path")
3. つかってみる
フォントを準備します。今回は、dafont.comからダウンロードしてみました。
早速pathを描いてみます。
library(string2path)
library(ggplot2)
dat <- string2path("STRING", "./fonts/Gready_PERSONAL_USE_ONLY-Bold.otf")
dat <- tibble::rowid_to_column(dat)
ggplot(dat) +
geom_path(aes(x, y, group = path_id, colour = factor(glyph_id))) +
theme_minimal()

塗りつぶしもできます。
ttf_file <- "./fonts/consola.ttf"
d <- string2fill("STRING", ttf_file)
ggplot(d) +
geom_polygon(aes(x, y, group = triangle_id, fill = factor(triangle_id %% 7)), colour = "grey", size = 0.1) +
theme_minimal() +
coord_equal() +
theme(legend.position = "none") +
scale_fill_viridis_d(option = "H")

4. さいごに
まだまだ色んな機能があるようです。おもしろいですね!