0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【備忘録】Raincloud plot

Last updated at Posted at 2023-02-22

はじめに

2要因2×2のデータセットでRaincloud plotを作るだけの備忘録。
完成形はこんな感じ↓

Rplot.jpeg

目次

  1. 下準備
  2. グラフを描画
  3. グラフを保存
  4. 参考

下準備

今回使うデータ。
要因Aが2水準(a1, a2)、要因Bが2水準(b1, b2)。

id <- rep(seq(1, 30, 1), 4)
A <- rep(c(rep('a1', 30), rep('a2', 30)), 2)
B <- c(rep('b1', 60), rep('b2', 60))

a1b1 <- c(rnorm(30, mean=15, sd=5))
a2b1 <- c(rnorm(30, mean=30, sd=5))
a1b2 <- c(rnorm(30, mean=20, sd=5))
a2b2 <- c(rnorm(30, mean=25, sd=5))

data <- data.frame(id, A, B, Value  = c(a1b1, a2b1, a1b2, a2b2))


data

グラフを描画

# install.packages("ggrain")
library(ggrain)

Graph <- ggplot(data[data$B %in% c('b1', 'b2'),], aes(B, Value, fill = A)) +
  geom_rain(alpha = .5, rain.side = 'f2x2', id.long.var = "id") +
  theme_classic() +
  facet_wrap(~A) +
  scale_fill_manual(values=c("dodgerblue", "darkorange")) +
  guides(fill = 'none', color = 'none') +
  ggtitle("Raincloud plots")

plot(Graph)

グラフを保存

ggsave(file = "名前.png", plot = Graph)

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?