色々なビジュアライゼーションを描いてみた by R

Rで描いた、いろいろなビジュアライゼーションを集めました。

基本的には、ggplotで描いていますが、
ggplotでの表現が煩雑になる場合は、他のライブラリも使用しています。

* デフォルトで読み込むライブラリ

```R:R
library(dplyr)
library(ggplot2)
```

# 属性間の比較
## 表（単純なもの）

```R:R
library(gridExtra)
d <- head(iris)
grid.table(d)
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/23ec00a8-1606-d1be-87c9-c4cf3228a78d.png)

## 表（フォーマット指定）

```R:R
library(formattable)
library(tibble)
data(mtcars)
mtcars <- rownames_to_column(mtcars, var=" ")

formattable(mtcars, 
            list(' ' = formatter("span", style = ~ style(color = "black", font.weight = "bold")), 
                 'mpg' = color_bar("#FAA18B"), 
                 'disp' = color_tile("white", "skyblue"),
                 area(col=c(9:12)) ~ formatter("span", 
                                               style = x ~ style(color = ifelse(x < 3, "red", "black")))
                 )
            )
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/882e3097-a247-926c-4b9a-1e61a71834de.png)

## 表（スパークライン付加）
```R:R
library(formattable)
library(sparkline)
library(tidyverse)

# データ準備
data(iris)
iris %>%
  group_by(Species) %>%
  summarise(n=n(),
        Sepal.Length.mean=mean(Sepal.Length)) -> df

# Speciesごとの数値データを、sparkline()に入れてオブジェクトを作成、
# それをhtml文字列に変換する
Sepal.Length.bySpecies <- split(iris, iris$Species)
for(type in c("bar", "box", "line")){
  Sepal.Length.bySpecies %>%
    map(~ sparkline(.$Sepal.Length, type = type)) %>%
    map(~ as.character(htmltools::as.tags(.))) -> spakline.htmlstr
  df[[type]] <- spakline.htmlstr
}

# formattable()でフォーマットし出力
out = as.htmlwidget(formattable(df))
out$dependencies = c(out$dependencies, htmlwidgets:::widget_dependencies("sparkline", "sparkline"))
out
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/91fca055-e8e7-ee54-8058-13ac13b9bd9c.png)


## 縦棒グラフ
```R:R
ggplot(BOD, aes(x=Time, y=demand)) +
  geom_col()
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/404c24c1-c011-1ac1-e9c3-ffc0e4d01dd9.png)

## 横棒グラフ
```R:R
ggplot(BOD, aes(x=demand, y=Time)) +
  geom_col()
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/aa1acdb3-30ae-b4de-9052-9e598f6f7ff7.png)

## クリーブランドのドットプロット
```R:R
# 描画用データ準備
df <- data.frame(state.x77)
df["Name"] <- rownames(df)

# geom_segment と geom_point を組み合わせることで描画
df[df$Population < 3000, ] %>%
  ggplot(aes(y=reorder(Name, Population), x=Population, color=Population)) +
  geom_segment(aes(yend=Name), xend=0) +
  geom_point(size=4) +
  theme(panel.grid.major.y=element_blank()) +
  ylab("U.S. state")
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/cfd357de-9c64-51b4-fb4f-7d2d69ca5752.png)

## ヒートマップ
```R:R
# 描画用データ準備
df <- data.frame(occupationalStatus)

#geom_rasterで描画。（geom_tileでも同じ図を描ける）
ggplot(df, aes(x=origin, y=destination, fill=Freq)) +
  geom_raster() 
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/bfa07cc1-35dc-9b35-bfb8-f57adc01868e.png)

## ヒートマップ + グラフ
superheatを使った色々な描き方は、[こちら](https://qiita.com/tomiyou/items/7aed2f4f0f7343384f8e)でも少し詳しく記載しています。

```R:R
library(superheat)
superheat(mtcars,scale=TRUE,
          yr=mtcars$mpg, 
          yr.plot.type="bar", 
          yr.axis.name="mpg",
          yr.plot.size=0.5)
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/d6f0f65b-80f1-db55-5073-4dbc4ad8afce.png)

# 時系列の比較
## 折れ線グラフ
```R:R
ggplot(economics, aes(x=date, y=uempmed)) +
  geom_line()
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/8ee4187a-f01a-02de-fbb2-cc951722351d.png)


## 面グラフ 
```R:R
ggplot(economics, aes(x=date, y=uempmed)) +
  geom_area(fill="skyblue2")
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/ea13fcf1-452c-7b1f-7dde-4e31175e6dc2.png)


## 積み上げ面グラフ
```R:R
library(tidyr)

# データ準備
# データが縦持ちの形式となっている必要がある
# WorldPhones
#      N.Amer Europe Asia S.Amer Oceania Africa Mid.Amer
#1951  45939  21574 2876   1815    1646     89      555
#1956  60423  29990 4708   2568    2366   1411      733
#1957  64721  32510 5230   2695    2526   1546      773
#...

#---↓↓↓---

#   Year  Country Users
#1  1951   N.Amer 45939
#2  1956   N.Amer 60423
#3  1957   N.Amer 64721
#4  1958   N.Amer 68484
#...

df <- data.frame(WorldPhones) %>%
  tibble::rownames_to_column("Year") %>%
  gather(key="Country", value="Users", -Year)
df$Year <- as.integer(df$Year)

ggplot(df, aes(x=Year, y=Users, fill=Country)) + 
  geom_area() +
  scale_fill_brewer("blues")
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/44bbdbcb-8d54-c570-80ec-0bc465b5dbe4.png)


## スロープグラフ

```R:R
library("ggrepel") #geom_pointのラベル位置を適当に調整するために使用

# データ準備
df <- data.frame(year=c(2020, 2021, 2020, 2021, 2020, 2021), 
                 grp=c("A", "A", "B", "B", "C", "C"),
                 val=c(21.4, 18.4, 32.0, 26.3, 24.8, 28.2))

ggplot(df, aes(x=factor(year), y=val, label=val, group=grp, colour=grp)) +
  geom_line() +
  geom_point(size=2) +
  geom_text_repel() +
  ylim(0, 40) +
  xlab("year")
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/15190842-7e97-31f2-f825-e414b821f469.png)

## バンプチャート

```R:R
library(ggbump) #install_github("davidsjoberg/ggbump")

# データ準備
df <- data.frame(country=c(rep("A", 4), rep("B", 4), rep("C", 4), rep("D", 4)),
           year=rep(c(2017, 2018, 2019, 2020), 4),
           rank=c(4,2,1,3, 1,3,2,4, 3,1,3,2, 2,4,4,1))

ggplot(df, aes(year, rank, color = country)) +
  geom_point(size = 7) +
  geom_text(data = df %>% filter(year == min(year)),
            aes(x = year - .1, label = country), size = 5, hjust = 1) +
  geom_text(data = df %>% filter(year == max(year)),
            aes(x = year + .1, label = country), size = 5, hjust = 0) +
  geom_bump(size = 2, smooth = 8) +
  scale_x_continuous(limits = c(2016.6, 2020.4),
                     breaks = seq(2017, 2020, 1)) +
  theme(legend.position = "none",
        panel.grid.major = element_blank()) +
  labs(y = "RANK",
       x = NULL) +
  scale_y_reverse() 
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/703876f9-f1f5-4126-55c7-25257c82e253.png)

## （分岐させた）色塗り線グラフ
```R:R

# データ準備
scaled_mtcars <- mtcars %>%
  scale() %>%
  data.frame() %>%
  mutate(positive=mpg>0)

ggplot(scaled_mtcars, aes(x=rownames(mtcars), y=mpg, fill=positive)) +
  geom_col() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        legend.position = 'none')  
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/49ae0929-4bc3-879c-669f-4320612310c1.png)


# 分布の把握
## ヒストグラム
ggplotのヒストグラムについては、[こちら](https://qiita.com/tomiyou/items/4e1532b48a6fa58e92df)にも少し詳しく記載しています。

```R:R
ggplot(iris, aes(x=Sepal.Length)) +
  geom_histogram(colour = "gray10", fill = "dodgerblue4")
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/5e79d8d5-6ecb-5a41-a4a0-3222dc1b00b3.png)


## 密度曲線 
```R:R
ggplot(iris, aes(x=Sepal.Length, fill=Species)) +
  geom_density(position="identity", alpha=0.6) +
  xlim(3.9, 8.4)
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/4e01058d-6916-5923-1bf7-0813bd669645.png)

## ジョイプロット
```R:R
library(ggridges)
library(ggplot2)

ggplot(iris, aes(x = Sepal.Length, y = Species, fill = Species)) +
  geom_density_ridges() +
  theme_ridges() + 
  theme(legend.position = "none")
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/49393708-4c9e-3a44-db42-b07ee9601738.png)

## ドットプロット（ウィルキンソン）
```R:R
ggplot(iris, aes(x=Sepal.Length)) +
  geom_dotplot(fill="skyblue1")
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/6267770b-6e8e-138a-dd31-121723942b19.png)

## ダンベルチャート
```R:R
library(ggalt) # install_github("hrbrmstr/ggalt")
data <- data.frame(USPersonalExpenditure)
data["category"] <- rownames(data)

ggplot(data, aes(x=X1940, xend=X1945, y=category, group=category)) +
  geom_dumbbell(size_x = 1.5,
                size_xend = 1.5) +
  xlab("1940 -1945")
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/396cfc16-1bc4-0f4f-0aa8-0cec9ffa9f5f.png)

## バタフライチャート
```R:R
#データ作成
data <- data.frame(
  agegp=rep(c("0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80"), 2),
  gender=c(rep("male", 8), rep("female", 8)),
  num=rep(c(100, 120, 140, 160, 180, 160, 140, 120), 2))

#片方の属性の値をマイナスにして「対」を表現する
data <- mutate(data, num=ifelse(gender=="female", -num, num))

#x軸のラベルをつくる
#上でマイナスにした部分を加味して補正したbreakとラベルを作成
max_num <- max(abs(data$num))
d <- diff(range(-max_num, max_num))/6
brks <- seq(-max_num, max_num, d)
lbls = as.character(c(seq(max_num, 0, -d), seq(d, max_num, d)))

#geom_barで描画
ggplot(data, aes(x = num, y = agegp, fill = gender)) +
  geom_bar(stat = "identity", width = .6) +
  scale_x_continuous(breaks = brks, 
                     labels = lbls)
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/b2592671-c335-4a83-035c-4327bdda6570.png)

## 箱ひげ図
```R:R
ggplot(iris, aes(x = Species, y=Petal.Width))+
  geom_boxplot() 
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/ffafdb92-a223-3315-73e5-ae3c6b5c78b6.png)

## バイオリンプロット
```R:R
ggplot(iris, aes(x = Species, y=Petal.Width))+
  geom_violin() 
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/92699763-5970-3864-d954-c68e51a2a701.png)

## 2次元の密度プロット
```R:R
ggplot(iris, aes(x = Petal.Length, y=Petal.Width)) +
  geom_point() +
  stat_density2d(aes(alpha=..density..), geom="tile", contour = F)
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/e0988a6e-1038-2c49-a9d1-7a9203cffba2.png)

# 相関の把握
## 散布図 
```R:R
ggplot(faithful, aes(x=eruptions, y=waiting)) +
  geom_point() +
  stat_smooth(method=lm) # 傾向線をプロット
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/bc892f02-228f-41a7-36b8-143e5581f1d0.png)

## 散布図行列
```R:R
#ggplotでは散布図行列を作成できないの手軽なpairsを使用
pairs(iris)
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/84eb74fe-9239-6ad7-5354-acc2144606dd.png)

## 相関行列
```R:R
library(corrplot)
cor_mtcars <- cor(mtcars)
corrplot(cor_mtcars)
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/c5901b81-36bb-64de-fd6d-2375c7252417.png)

## パックドバブルチャート
```R:R
library(hpackedbubble)
hpackedbubble(CO2$continent, CO2$country, CO2$CO2,
              packedbubbleZmax = 10000, split = 0)
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/1509f3ec-4e06-be6a-79ac-2b160bfd8f13.png)

## バルーンプロット
```R:R
ggplot(mtcars, aes(x=hp, y=mpg, size=disp)) +
  geom_point(shape=21, colour="black", fill="cornsilk") +
  scale_size_area(max_size=10)
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/2b2e1e11-2bbf-9c42-362e-c4c1ce215637.png)

# 内訳の比較
## 積み上げ棒グラフ
```R:R
#データ準備
df <- data.frame(Titanic) %>%
  group_by(Survived, Class) %>%
  summarize(n=n(), mean=mean(Freq))
```

* 積み上げ縦棒グラフ

```R:R
ggplot(df, aes(x=Class, y=mean, fill=Survived)) +
  geom_col()
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/91865d6a-c5ef-e244-59b4-5c1ad17940b8.png)

* 積み上げ横棒グラフ

```R:R
ggplot(df, aes(x=mean, y=Class, fill=Survived)) +
  geom_col()
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/d5cf9c40-ec43-275c-6ce1-8beaa3c48885.png)

## ウォーターフォールチャート
```R:R
#install.packages("waterfalls")
library(waterfalls)

#ダミーデータ
df <- data.frame(x=c("name1", "name2", "name3", "name4", "name5", "name6"),
           y=c(100, 200, -100, 300, -200, -300))

#描画
waterfall(df)
```
![3005FB18-C052-4E82-998C-FC7559929E25.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/fd360589-26a7-5ec5-d98f-6ff091f77edb.png)


## バルーンプロット
```R:R
library(gplots)
balloonplot(Titanic[,, Age="Adult", Survived="Yes"],
            main="Titanic Class x Sex Table (Survived=Yes)")
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/865026f8-a8e9-8a89-494f-859f29f0f756.png)

## 円グラフ
* ggplotで描くのが難しいため、plotlyで描く

```R:R
library(plotly)
data <- data.frame(labels=c("A", "B", "C", "D"), values=c(30, 20, 60, 80))
#   labels values
#1      A     30
#2      B     20
#3      C     60
#4      D     80

plot_ly(data, labels = ~labels, values = ~values, type = "pie", sort=F) %>%
  layout(title="Pie Chart Sample")
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/e2e9ca24-78ed-150e-c416-8c2823d546cd.png)


## ドーナツグラフ 
* 円グラフ同様、plotlyで描く

```R:R
library(plotly)
data <- data.frame(labels=c("A", "B", "C", "D"), values=c(30, 20, 60, 80))
plot_ly(data, labels = ~labels, values = ~values, type = "pie", hole=0.6, sort=F) %>%
  layout(title="Pie Chart Sample")
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/d60db6db-5f46-5409-cc68-feb51ef7072e.png)

* ggplotで頑張るパターン
 
```R:R
df <- data.frame(name=c("A", "B", "C", "D"), 
                 ymin=c(0, 30, 60, 80), 
                 ymax=c(30, 60, 80, 100))
ggplot(df) +
  geom_rect(aes(fill=name, ymin=ymin, ymax=ymax, xmax=4, xmin=3)) +
  coord_polar(theta="y") + xlim(c(0,4))
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/30c5f931-e69e-efb8-83d6-7532fb0074fe.png)


## 階層型ドーナツグラフ 
## 極座標プロット
```R:R
ggplot(iris, aes(x=Sepal.Length, fill=Species)) +
  geom_histogram(colour = "gray10") +
  coord_polar()
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/5efc0623-18ad-0f80-623e-c60a119c70c8.png)


## ツリーマップ 
* treemapifyを使用

```R:R
library(treemapify)

#データ作成
mobility <- c(rep("train",3),rep("bus",3),rep("taxi",3))
count <- c(c(100, 90, 80), c(120, 90, 70), c(60, 30, 40))
year <- rep(c("2018", "2019", "2020"), 3)
df <- data.frame(mobility, count, year)

ggplot(df, aes(area = count, fill = year, label=mobility, subgroup=year)) +
  geom_treemap(aes(alpha = count)) +
  geom_treemap_text(colour = "white", place = "centre") +
  geom_treemap_subgroup_text(place = "centre", grow = T, alpha = 0.2) 
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/56f35db2-65c9-3008-96fe-728e5f904f08.png)

* treemapを使用

```R:R
library(treemap)
data <- data.frame(index=rownames(mtcars),
                   value=mtcars$mpg)

rainbow_color <- rainbow(47,s=0.4) #set colors
treemap(data,
        index=c("index"),
        vSize="value",
        type="index",
        palette = rainbow_color)
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/ce217160-4644-78ed-0f3e-7723d0627c70.png)

## モザイクプロット
```R:R
library(vcd)
mosaic(HairEyeColor)
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/952a8b6e-b884-7748-58af-cf6b5bc1090e.png)

## レーダーチャート
```R:R
library(ggradar)
library(scales)

mtcars %>%
  tibble::rownames_to_column("group") %>%
  mutate_each(funs=rescale, -group) %>% 
  tail(4) %>% select(1:10) -> mtcars_radar

ggradar(mtcars_radar) 
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/f88a6500-aaf8-ace9-a8dd-83a7e18908e8.png)

## 面積グラフ
```R:R
# データ作成
xs <- c()
ys <- c()
ds <- c()
for(x in 1:10){
  for(y in 1:10){
    xs <- c(xs, x)
    ys <- c(ys, y)
    if(x <= 3 & y <= 3){
      ds <- c(ds, "1")
    }else if(x <= 5 & y <=5){
      ds <- c(ds, "2")
    }else{
      ds <- c(ds, "3")
    }
  }
}
df <- data.frame(x=xs, y=ys, d=ds)

ggplot(df) + 
  scale_x_continuous(breaks=NULL) +
  scale_y_continuous(breaks=NULL) +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_blank(),
        panel.background = element_blank(),
        legend.position = 'none') +
  geom_tile(aes(x=xs,y=ys,fill=ds), width=1, height=1, size=0.5, colour="white") +
  scale_fill_manual(values=c("#00B0F0", "#808080", "#C0C0C0"))
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/a08a6110-a145-6b1e-1e31-3c736d573ded.png)

# クラスタリング
## 樹形図
```R:R
scaled_mtcars <- scale(mtcars)
hc <- hclust(dist(scaled_mtcars))
plot(hc, hang=-1)
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/4668fccd-dd0f-1407-32b1-636914782586.png)

# その他
## スコアカード（単純なテキスト）
```R:R
rects <- data.frame(x=1:3,
                    text=c(500, 2190, -100),
                    colors=c("gray", "pink", "skyblue"))

ggplot(rects, aes(x, y = 0, label = text)) +
  geom_tile(width = .9, height = .8, fill="white", colour="black") + 
  geom_text(aes(color = colors), size=12) +
  scale_color_identity(guide = "none") +
  coord_fixed() + 
  theme_void()
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/97014cb5-a131-9be1-508b-2592c706c092.png)

## カレンダープロット
```R:R
library(calendR)

# データ作成
date <- seq(as.Date("2020-01-01"), as.Date("2020-12-31"), by="day")
value <- random.walk <- cumsum(rnorm(n=length(date))) #ランダムウォーク

calendR(year=2020,
        weeknames = c("日", "月", "火", "水", "木", "金", "土"), 
        
        special.days=value,
        gradient = TRUE,
        special.col = "pink",
        low.col = "lightblue",
        legend.pos = "right",
        legend.title = "Legend",
        
        font.family = "HiraKakuProN-W3") #文字化け対策（MACの場合）
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/a1c4a089-3858-a383-7f13-daed76e49451.png)

## ベクトルフィールド
```R:R
n <- 50
df <- data.frame(x=runif(n),y=runif(n),dx=rnorm(n),dy=rnorm(n))
ggplot(data=df, aes(x=x, y=y)) +
  geom_segment(aes(xend=x+dx, yend=y+dy), arrow = arrow(length = unit(0.2,"cm")))
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/8ab989d9-21d9-eac1-2600-b5deb94e2b23.png)

## ネットワークグラフ
```R:R
library(igraph)
network_df <- data.frame(from=c(1,2,1,1,3,2,5,6,5,1),
                         to  =c(2,3,3,4,2,4,5,1,7,7))
g <- graph.data.frame(network_df)
plot(g)
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/4db9d509-c9de-6154-329c-c2a6711b7a65.png)


## ワードクラウド
```R:R
#stopwordsを使いランダム的にサイズ設定して表示していますが、これ自体にはとくに意味はありません。
library(wordcloud2)
library(stopwords)
words <- stopwords::stopwords("ja", source = "marimo")
df <- data.frame(words=words, freq=rnorm(length(words)))
wordcloud2(df)
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/254095/f1e5c2d2-37de-8d02-92a3-a408140c6f9c.png)